Jump to content

Row selection problem


Lee-Bartlett

Recommended Posts

I am trying to select the row in my db which is echoed on a page. This code makes the button work on the page, a little pop up of a map with specific cords. Only problem is it only goes to the first entry and not the row it is in. Heres the code for both pages.

 

-- The php popup page. --

 

<?php
$link = mysql_connect('localhost','root', 'password');
if($link && mysql_select_db('nexodom_test'))
  {
  $sql = "SELECT * FROM tblbasicform WHERE id='id'";
  $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';
?>

 

-- Page where the db and the button which makes the pop up work. --

 

<?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> </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))
{

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>

Link to comment
https://forums.phpfreaks.com/topic/129996-row-selection-problem/
Share on other sites

is the popup wifi.php?

 

In your popup's query, you are selecting a row WHERE id = 'id', what exactly does that do? are you ids strings and one happens to be the string "id"?

 

You more than likely need to pass the id to wifi.php like wifi.php?id=some_id and then in wifi.php validate that $_GET['id'] is a number and use that variable in your query

 

WHERE id = {$cleaned_varified_id}

in the link that opens the popup, you need to append ?id=9 to the page's name ie popup.php?id=9 to tell the query get the ninth entry.

 

Looking at your code, you need to edit both the JavaScript function openWindow() and the link that is used to call that function

 

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

 

you could change that to

 

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

 

and update your openWindow function to this

 

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')

}

i get these error messages

 

Warning: Cannot modify header information - headers already sent by (output started at /home/nexodom/public_html/website/popup.php:5) in /home/nexodom/public_html/website/popup.php on line 12

 

Warning: Cannot modify header information - headers already sent by (output started at /home/nexodom/public_html/website/popup.php:5) in /home/nexodom/public_html/website/popup.php on line 13

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.