Link to home
Start Free TrialLog in
Avatar of Lee-Bartlett
Lee-Bartlett

asked on

Only selecting 1 row in the db

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

Avatar of raminhos
raminhos
Flag of Portugal image

Can you show the fields of yout database?

Is your id key ? is autoincrement ?
Avatar of Lee-Bartlett
Lee-Bartlett

ASKER

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

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

That broke the popup window
Maybe i need to do a $_GET? to get the longitude, latitude and ID oveR?
Check this answer i gave:

https://www.experts-exchange.com/questions/23842891/How-would-i-add-varibles-to-a-url.html?cid=236&anchorAnswerId=22792201#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

And yes...depending of your php.ini configuration, you might need to use $_GET
The window opens again, i need to know where im going wrong that it is only selecting only 1 row the first one.  
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 ?
Yes, take a look at the site...

www.nexodom.com/website/wifi.php
ASKER CERTIFIED SOLUTION
Avatar of raminhos
raminhos
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
That works great :D ill reveiw the code and see where i went wrong :) ty
Glad i could help :)