Forum Moderators: coopster
I'm going to be using PHP/JavaScript/MySQL for it. The basic layout is this:
On the website, a user can click a link, JavaScript takes over and furnishes a pop-up window. In this window I would need information to be displayed according to what link they clicked.
So let's start like this...On "index.php" there are three links:
Link A
Link B
Link C
Link A - Contains information about cars, listed in MySQL database "info" as line 1.
Link B - Information on houses, MySQL database "info" as line 2.
Link C - Information on pets, MySQL database "info" as line 3.
I suppose it might help if I show you the coding I'm using..
<script>
var newwindow;
function box(url)
{
newwindow=window.open(url,'name','height=400,width=200');
if (window.focus) {newwindow.focus()}
}
</script>
The links are:
<a href="javascript:box('popup.php');">Link</a>
"popup.php" would contain the code for connecting to the MySQL database to retrieve the relevant information.
My only question is...How do I tell it what row in the table to display?
Let's say my table is setup like this:
Column 1 - ID
Column 2 - Name
Column 3 - Description
My only guess would be to use the ID as a reference, but I'm not sure how to do that..So..I think that's my question.
I know this post is probably really confusing, so..If anyone needs clarification, just ask.
Also, after I get some help on that, I was wondering if anyone could lend their knowledge on setting up a so-called "Admin Interface".
This would generally be a form to input data into the MySQL table for the links..I'm guessing it would be something like this:
<?php
$dbhost='localhost';
$dbusername='';
$dbuserpass='';
$dbname='';
mysql_connect ($dbhost, $dbusername, $dbuserpass);
if (!mysql_select_db($dbname)) die(mysql_error());
$id = "";
$name = "";
$desc = "";
$query1 = "INSERT INTO info (id,name,description) VALUES ('".$id."','".$name."','".$desc."')";
mysql_query($query1)or die(mysql_error());
?>
But I'm not sure how to make a web-interface to handle entering the variables. That script would just be run from a browser, but you have to fill in the variables by hand in the script.
Thanks in advance!
Regards,
Ken
It should just be a case of passing the id of each link to popup.php on the query string - just as form variables are submitted using a form with the "GET" method. Your links would look something like this:
<a href="javascript:box('popup.php?id=1');">Link A</a>
<a href="javascript:box('popup.php?id=2');">Link B</a>
<a href="javascript:box('popup.php?id=3');">Link C</a>
Then, in popup.php, you simply query the database using an SQL statement with a WHERE clause something like:
$sql = "SELECT * FROM info WHERE id=".mysql_escape_string($_GET["id"]);
Strictly speaking the mysql_escape_string function is not required but you should use it because the value of $id is untrusted.
<?php
$dbhost='localhost';
$dbusername='#*$!';
$dbuserpass='#*$!';
$dbname='info';
mysql_connect ($dbhost, $dbusername, $dbuserpass);
if (!mysql_select_db($dbname)) die(mysql_error());
$sql = "SELECT * FROM info WHERE id=".mysql_escape_string($_GET["id"])";
$result = mysql_query($query) or die('Error, query failed');
while ($row = mysql_fetch_array($result)) {
echo "<table border='5'>
<tr>
<td>
'.$row['name'].'
</td>
</tr>
<tr>
<td>
'.$row['description'].'
</td>
</tr>
</table>";
}
?>
Just not seeing why it's not working...
Oh yeah..It's not giving errors, it's just...Nothing displays. :)
I guess it would help to let you know I'm running PHP 4.4.0, MySQL 4.1.14, Apache 2.0.54 On Win Server 2003
<?php
$dbhost='localhost';
$dbusername='root';
$dbuserpass='password';
$dbname='database';mysql_connect ($dbhost, $dbusername, $dbuserpass);
if (!mysql_select_db($dbname)) die(mysql_error());
$query = "SELECT * FROM info WHERE id=".mysql_escape_string($_GET["id"]);
$result = mysql_query($query) or die('Error, query failed');
while ($row = mysql_fetch_assoc($result)) {
echo $row['id'];
echo $row['name'];
echo $row['description'];
}
?>
[edited by: coopster at 4:35 pm (utc) on May 8, 2006]
[edit reason] generalized information [/edit]