• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

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

0
Lee-Bartlett
Asked:
Lee-Bartlett
  • 8
  • 6
1 Solution
 
raminhosCommented:
Can you show the fields of yout database?

Is your id key ? is autoincrement ?
0
 
Lee-BartlettAuthor Commented:
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
 
raminhosCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Lee-BartlettAuthor Commented:
That broke the popup window
0
 
Lee-BartlettAuthor Commented:
Maybe i need to do a $_GET? to get the longitude, latitude and ID oveR?
0
 
raminhosCommented:
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
 
raminhosCommented:
And yes...depending of your php.ini configuration, you might need to use $_GET
0
 
Lee-BartlettAuthor Commented:
The window opens again, i need to know where im going wrong that it is only selecting only 1 row the first one.  
0
 
raminhosCommented:
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
 
Lee-BartlettAuthor Commented:
Yes, take a look at the site...

www.nexodom.com/website/wifi.php
0
 
raminhosCommented:
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
 
raminhosCommented:
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
 
Lee-BartlettAuthor Commented:
That works great :D ill reveiw the code and see where i went wrong :) ty
0
 
raminhosCommented:
Glad i could help :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now