Solved

Only selecting 1 row in the db

Posted on 2008-10-24
14
292 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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
 

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

828 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