Solved

Only selecting 1 row in the db

Posted on 2008-10-24
14
287 Views
Last Modified: 2013-12-13
How do i get this code to select the row in the db i click on. There is a button in each row which pops up a map but it only pops up row 1. i tried somthing like select * from table where id='id' somthing like that but didnt work. Here is the code.


<?php

$link = mysql_connect('localhost','root', 'password');

if($link && mysql_select_db('nexodom_test'))

  {

  $sql = "select * from tblbasicform";

  $res = mysql_query($sql);

  $row = mysql_fetch_array($res);
 

  $addr =

  'http://maps.google.com/staticmap?center='.$row[latitude].','.$row[longitude].'&zoom=12&size=400x400&key=ABQIAAAAgnVrcDn5i-V_BsqvXy3j8RRle8Rt1EK93-n5qGMjk9aCuGqlpBQ2sCqItCc79KzQksp90dVmLGk45w';
 

header("Expires: Thu, 01 Jan 1970 00:00:01 GMT");

header("Location: $addr");
 

//echo "We will call this URL: <b>$addr</b>";

//exit();

  }
 

echo 'Cannot connect to database';

?>

Open in new window

0
Comment
Question by:Lee-Bartlett
  • 8
  • 6
14 Comments
 
LVL 3

Expert Comment

by:raminhos
ID: 22799015
Can you show the fields of yout database?

Is your id key ? is autoincrement ?
0
 

Author Comment

by:Lee-Bartlett
ID: 22799079
Yes id is auto and key, that popup.php is connected to this page.  the pop up works when a buttopn is clicked
<?php  require_once("includes/db_connection.php"); ?>
 

<html>
 

<head>
 

<script language='javascript' type='text/javascript'>

<!--

function openWindow() {

 popupWin = window.open('popup.php', 'popup',

'width=550,height=400,resizable=no,scrollbars=yes,toolbar=no,screenX=0,screenY=0,Top=0,Left=0')

}

// -->

</script>

</head>
 

<body onLoad="load()" onUnload="GUnload()" >

<table width="802" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#000000">

  <tr>

    <td colspan="2" bgcolor="#0099FF"><p>&nbsp;</p>

    <p align="center" class="style1">Nexodom.com</p>      

    <p>&nbsp;</p></td>

  </tr>

  <tr>

    <td width="102" height="318" align="left" valign="top"><p><a href="index.html">Home</a><br>

        <a href="wifi.php">WIFI Hot Spots</a></p>

    </td>

    <td width="674" align="left" valign="top"><p align="center">WIFI Hot Spot List</p>

    

<?php
 

$sql = "SELECT * from tblbasicform";

$res = mysql_query($sql) or die(mysql_error());
 

echo "<table border=2>";

echo "<tr> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Latitude</td><td>Longitude</td> <td>Free or Paid</td><td>New</td></tr>";

while($row = MYSQL_FETCH_ARRAY($res))

{
 

echo "<tr><td>".$row['name']."</td>";

echo "<td>".$row['email']."</td>";

echo "<td>".$row['buissnes_name']."</td>";

echo "<td>".$row['location']."</td>";

echo "<td>".$row['latitude']."</td>";

echo "<td>".$row['longitude']."</td>";

echo "<td>".$row['type']."</td>";

echo "<form>";

echo "<td><input type=\"button\" onClick=\"openWindow(); return false;\" value=\"Pop Up Map\">";

echo "</td></tr>";

echo "</form>";
 

}

?>
 
 
 
 

</table><br>

<a href="userform.php">Submit a WIFI hotspot</a>

<br />

<br />
 

</body>

</html>

Open in new window

0
 
LVL 3

Expert Comment

by:raminhos
ID: 22799234
Try this change your openwindow java to send id variable..

Then select * from table where id = $id


<script language='javascript' type='text/javascript'>

<!--

function openWindow() {

 popupWin = window.open('popup.php?id=<?=$id?>', 'popup',

'width=550,height=400,resizable=no,scrollbars=yes,toolbar=no,screenX=0,screenY=0,Top=0,Left=0')

}

// -->

</script>

Open in new window

0
 

Author Comment

by:Lee-Bartlett
ID: 22799405
That broke the popup window
0
 

Author Comment

by:Lee-Bartlett
ID: 22799430
Maybe i need to do a $_GET? to get the longitude, latitude and ID oveR?
0
 
LVL 3

Expert Comment

by:raminhos
ID: 22799449
Check this answer i gave:

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_23842891.html?cid=236#a22792201

i show an example:


<?php

 

// your code...

 

?>

 

<script> 

function abrir()

{

window.open('http://google.com/<?=$images?>','Google','toolbar=no','directories=no','status=no','menubar=no','location=no','status=no','resizable=yes');

};

</script>

 

<?php

 

echo "<form>";

echo "<td><INPUT type='submit' name=submit value='New Window' onclick="abrir()";>";

echo "</td></tr>";

echo "</form>";

 

?> 

Open in new window

0
 
LVL 3

Expert Comment

by:raminhos
ID: 22799452
And yes...depending of your php.ini configuration, you might need to use $_GET
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:Lee-Bartlett
ID: 22799470
The window opens again, i need to know where im going wrong that it is only selecting only 1 row the first one.  
0
 
LVL 3

Expert Comment

by:raminhos
ID: 22799538
I don't understand what you want..

When user clicks the fomr button you open popup.php..

What should popup.php show ?

Google map with coordinates that you get from your databse ?
0
 

Author Comment

by:Lee-Bartlett
ID: 22799611
Yes, take a look at the site...

www.nexodom.com/website/wifi.php
0
 
LVL 3

Accepted Solution

by:
raminhos earned 500 total points
ID: 22799838
OK. i did something like that..

I needed to open a popup depending the button the user clicked.

In your case you need to send the id of the database row you want to get the coordinates, right ?

Didn't test the code..but..


<?php  require_once("includes/db_connection.php"); ?>
 

<html>
 

<body onLoad="load()" onUnload="GUnload()" >

<table width="802" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#000000">

  <tr>

    <td colspan="2" bgcolor="#0099FF"><p> </p>

    <p align="center" class="style1">Nexodom.com</p>

    <p> </p></td>

  </tr>

  <tr>

    <td width="102" height="318" align="left" valign="top"><p><a href="index.html">Home</a><br>

        <a href="wifi.php">WIFI Hot Spots</a></p>

    </td>

    <td width="674" align="left" valign="top"><p align="center">WIFI Hot Spot List</p>
 

<?php
 

$sql = "SELECT * from tblbasicform";

$res = mysql_query($sql) or die(mysql_error());
 

echo "<table border=2>";

echo "<tr> <td>Name</td><td>Email</td><td>Buissnes Name</td><td>Location</td><td>Latitude</td><td>Longitude</td> <td>Free or Paid</td><td>New</td></tr>";

while($row = MYSQL_FETCH_ARRAY($res))

{

$id = $row['id'];

?>

<script language='javascript' type='text/javascript'>

<!--

function openWindow<?=$id?>() {

 popupWin = window.open('popup.php?id=<?=$id?>', 'popup','width=550,height=400,resizable=no,scrollbars=yes,toolbar=no,screenX=0,screenY=0,Top=0,Left=0')

}

// -->

</script>

<?

echo "<form method=post name=pop$id>";

echo "<tr><td>".$row['name']."</td>";

echo "<td>".$row['email']."</td>";

echo "<td>".$row['buissnes_name']."</td>";

echo "<td>".$row['location']."</td>";

echo "<td>".$row['latitude']."</td>";

echo "<td>".$row['longitude']."</td>";

echo "<td>".$row['type']."</td>";

echo "<form>";

echo "<td><input type=\"button\" onClick=\"openWindow$id(); return false;\" value=\"Pop Up Map\">";

echo "</td></tr>";

echo "</form>";
 

}

?>
 
 
 
 

</table><br>

<a href="userform.php">Submit a WIFI hotspot</a>

<br />

<br />
 

</body>

</html>

Open in new window

0
 
LVL 3

Expert Comment

by:raminhos
ID: 22799849
Of course in popup.php you must do another select * from table where id = $id

You might need to do first: $id = $_GET['id'];

and then redirect with the coordinates you retrieve from database
0
 

Author Comment

by:Lee-Bartlett
ID: 22799934
That works great :D ill reveiw the code and see where i went wrong :) ty
0
 
LVL 3

Expert Comment

by:raminhos
ID: 22799961
Glad i could help :)
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now