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
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}

Link to comment
Share on other sites

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

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.