Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
toplet159
Forum Newbie
Posts: 10 Joined: Sun Jul 11, 2004 1:20 pm
Post
by toplet159 » Sun Jul 11, 2004 1:20 pm
I have 2 tables one called eventslist and one called photogallery
My problem is that using this code it will only let me select from eventslist and not from photogallery
i will be left with id= or details=
if i changed the code to select from eventslist it will find id=1 or details=1
so can someone please tell me how to make it select from the other table
Code: Select all
<?php
echo "<table width="798" height="30" border="0" cellpadding="0" cellspacing="0">";
if (!$id && !$details){ $result = mysql_query("SELECT * FROM eventslist");
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
$f_price = number_format($price,2);
echo"
<tr>
<td valign="top" onmousedown="LmDown(this, 'menuentry_hovere')" onmouseup="LmUp('events6.php?id=$id')" onmouseover="LmOver(this, 'menuentry_hovere')" onmouseout="LmOut(this, 'menuentrye')">
<table border="0" cellpadding="0" cellspacing="0" class="eventstable">
<tr>
<td width="200" class="eventname">$eventname</td>
<td width="498" class="eventdescription">$description</td>
<td width="100" class="eventdate">$date</td>
</tr>
</table></td>
</tr>
";
}
}
elseif ($id && !$details) { $result = mysql_query("SELECT * FROM photogallery WHERE id='$id'");
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
$f_price = number_format($price,2);
echo" <table width="818" height="232" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="818" height="192" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic1"><img src="camera.jpg" width="190" height="190"></td>
<td width="10"> </td>
<td width="192"align="center" valign="middle" background="$pic2"><img src="camera.jpg" width="192" height="192"></td>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic3"><img src="picbg.gif" width="192" height="192"></td>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic4"><img src="picbg.gif" width="192" height="192"></td>
<td width="10"> </td>
</tr>
</table>
<table width="818" height="40" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="818" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="textbg.gif"><a href="events6.php?details=$details">Click for more Information</a></td>
<td> </td>
<td width="192" align="center" valign="middle" background="textbg1.gif">Lovely
Camera</td>
<td> </td>
<td width="192"> </td>
<td> </td>
<td width="192"> </td>
<td width="10"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
";
}
}
elseif (!$id && $details) {
$result = mysql_query("SELECT * FROM photogallery WHERE details='$details'");
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
$f_price = number_format($price,2);
echo"<table width="798" height="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="300">$pic</td>
</tr>
<tr>
<td height="100">$description</td>
</tr>";
}
}
echo "</table>\n";
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 11, 2004 1:28 pm
do you have register_globals on? look through the following's output to find out:
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 11, 2004 3:28 pm
yep.. register_globals is on..
toplet159
Forum Newbie
Posts: 10 Joined: Sun Jul 11, 2004 1:20 pm
Post
by toplet159 » Sun Jul 11, 2004 3:36 pm
so no idea how to get it to work?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 11, 2004 3:36 pm
from what I can tell without running it, it looks like it'd work.
toplet159
Forum Newbie
Posts: 10 Joined: Sun Jul 11, 2004 1:20 pm
Post
by toplet159 » Sun Jul 11, 2004 3:41 pm
it wont pick up $details from any other table other than eventslist
but if you type link?details=1 manually it will pick it up
otherwise it just finds link?details=
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 11, 2004 3:55 pm
post the table structures and some data from each..
moving topic to Databases
toplet159
Forum Newbie
Posts: 10 Joined: Sun Jul 11, 2004 1:20 pm
Post
by toplet159 » Sun Jul 11, 2004 3:59 pm
Code: Select all
#
# Table structure for table `eventslist`
#
CREATE TABLE eventslist (
id tinyint(4) NOT NULL auto_increment,
eventname varchar(50) NOT NULL default '',
description varchar(255) NOT NULL default '',
date varchar(50) NOT NULL default '',
pic1 varchar(50) NOT NULL default '',
PRIMARY KEY (id)
) TYPE=MyISAM;
#
# Dumping data for table `eventslist`
#
INSERT INTO eventslist VALUES (1,'party','good party','08/06/07','camera.jpg');
INSERT INTO eventslist VALUES (2,'','','','pic1.jpg');
#
# Table structure for table `photogallery`
#
CREATE TABLE photogallery (
details tinyint(4) NOT NULL auto_increment,
pic varchar(50) NOT NULL default '',
description varchar(50) NOT NULL default '',
PRIMARY KEY (details)
) TYPE=MyISAM;
#
# Dumping data for table `photogallery`
#
INSERT INTO photogallery VALUES (1,'sdgg','fdgfd');
INSERT INTO photogallery VALUES (2,'camera.jpg','dds');
INSERT INTO photogallery VALUES (3,'camera.jpg','udgubasdjdsabdsabj');
feyd | added
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 11, 2004 4:20 pm
using your table structures and data:
Code: Select all
<?php
mysql_connect('localhost','*********','*********');
mysql_select_db('*******');
echo "<table width="798" height="30" border="0" cellpadding="0" cellspacing="0">";
$id = (!empty($_GET['id']) ? $_GET['id'] : false);
$details = (!empty($_GET['details']) ? $_GET['details'] : false);
if (!$id && !$details){ $result = mysql_query("SELECT * FROM eventslist") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
//$f_price = number_format($price,2);
echo"
<tr>
<td valign="top"><a href="{$_SERVER['SCRIPT_NAME']}?id=$id">here</a>
<table border="0" cellpadding="0" cellspacing="0" class="eventstable">
<tr>
<td width="200" class="eventname">$eventname</td>
<td width="498" class="eventdescription">$description</td>
<td width="100" class="eventdate">$date</td>
</tr>
</table></td>
</tr>
";
}
}
elseif ($id && !$details) { $result = mysql_query("SELECT * FROM photogallery WHERE id='$id'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
//$f_price = number_format($price,2);
echo" <table width="818" height="232" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="818" height="192" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic1"><img src="camera.jpg" width="190" height="190"></td>
<td width="10"> </td>
<td width="192"align="center" valign="middle" background="$pic2"><img src="camera.jpg" width="192" height="192"></td>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic3"><img src="picbg.gif" width="192" height="192"></td>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic4"><img src="picbg.gif" width="192" height="192"></td>
<td width="10"> </td>
</tr>
</table>
<table width="818" height="40" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="818" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="textbg.gif"><a href="events6.php?details=$details">Click for more Information</a></td>
<td> </td>
<td width="192" align="center" valign="middle" background="textbg1.gif">Lovely
Camera</td>
<td> </td>
<td width="192"> </td>
<td> </td>
<td width="192"> </td>
<td width="10"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
";
}
}
elseif (!$id && $details) {
$result = mysql_query("SELECT * FROM photogallery WHERE details='$details'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
//$f_price = number_format($price,2);
echo"<table width="798" height="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="300">$pic</td>
</tr>
<tr>
<td height="100">$description</td>
</tr>";
}
}
echo "</table>\n";
?>Code: Select all
Unknown column 'id' in 'where clause'
toplet159
Forum Newbie
Posts: 10 Joined: Sun Jul 11, 2004 1:20 pm
Post
by toplet159 » Sun Jul 11, 2004 4:35 pm
Sorry about this but can you retest it with this code i accidently forgot to change a few things (been fiddling around trying to get this to work for ages)
also i have deleted something in the db tables
so if you could copy the db code again pls , thanks
Code: Select all
<?php
mysql_connect('localhost','*********','*********');
mysql_select_db('*******');
echo "<table width="798" height="30" border="0" cellpadding="0" cellspacing="0">";
$id = (!empty($_GET['id']) ? $_GET['id'] : false);
$details = (!empty($_GET['details']) ? $_GET['details'] : false);
if (!$id && !$details){ $result = mysql_query("SELECT * FROM eventslist") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
//$f_price = number_format($price,2);
echo"
<tr>
<td valign="top"><a href="{$_SERVER['SCRIPT_NAME']}?id=$id">here</a>
<table border="0" cellpadding="0" cellspacing="0" class="eventstable">
<tr>
<td width="200" class="eventname">$eventname</td>
<td width="498" class="eventdescription">$description</td>
<td width="100" class="eventdate">$date</td>
</tr>
</table></td>
</tr>
";
}
}
elseif ($id && !$details) { $result = mysql_query("SELECT * FROM photogallery WHERE details='$details'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
//$f_price = number_format($price,2);
echo" <table width="818" height="232" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="818" height="192" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic1"><img src="camera.jpg" width="190" height="190"></td>
<td width="10"> </td>
<td width="192"align="center" valign="middle" background="$pic2"><img src="camera.jpg" width="192" height="192"></td>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic3"><img src="picbg.gif" width="192" height="192"></td>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic4"><img src="picbg.gif" width="192" height="192"></td>
<td width="10"> </td>
</tr>
</table>
<table width="818" height="40" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="818" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="textbg.gif"><a href="events6.php?details=$details">Click for more Information</a></td>
<td> </td>
<td width="192" align="center" valign="middle" background="textbg1.gif">Lovely
Camera</td>
<td> </td>
<td width="192"> </td>
<td> </td>
<td width="192"> </td>
<td width="10"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
";
}
}
elseif (!$id && $details) {
$result = mysql_query("SELECT * FROM photogallery WHERE details='$details'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
//$f_price = number_format($price,2);
echo"<table width="798" height="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="300">$pic</td>
</tr>
<tr>
<td height="100">$description</td>
</tr>";
}
}
echo "</table>\n";
?>
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Jul 11, 2004 4:43 pm
Code: Select all
<?php
mysql_connect('localhost','*******','*******');
mysql_select_db('*******');
echo "<table width="798" height="30" border="0" cellpadding="0" cellspacing="0">";
$id = (!empty($_GET['id']) ? $_GET['id'] : false);
$details = (!empty($_GET['details']) ? $_GET['details'] : false);
if (!$id && !$details){ $result = mysql_query("SELECT * FROM eventslist") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
//$f_price = number_format($price,2);
echo"
<tr>
<td valign="top"><a href="{$_SERVER['SCRIPT_NAME']}?id=$id">here</a>
<table border="0" cellpadding="0" cellspacing="0" class="eventstable">
<tr>
<td width="200" class="eventname">$eventname</td>
<td width="498" class="eventdescription">$description</td>
<td width="100" class="eventdate">$date</td>
</tr>
</table></td>
</tr>
";
}
}
elseif ($id && !$details) { $result = mysql_query("SELECT * FROM photogallery WHERE details='$id'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
//$f_price = number_format($price,2);
echo" <table width="818" height="232" border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top"><table width="818" height="192" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic1"><img src="camera.jpg" width="190" height="190"></td>
<td width="10"> </td>
<td width="192"align="center" valign="middle" background="$pic2"><img src="camera.jpg" width="192" height="192"></td>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic3"><img src="picbg.gif" width="192" height="192"></td>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="$pic4"><img src="picbg.gif" width="192" height="192"></td>
<td width="10"> </td>
</tr>
</table>
<table width="818" height="40" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><table width="818" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="10"> </td>
<td width="192" align="center" valign="middle" background="textbg.gif"><a href="{$_SERVER['SCRIPT_NAME']}?details=$id">Click for more Information</a></td>
<td> </td>
<td width="192" align="center" valign="middle" background="textbg1.gif">Lovely
Camera</td>
<td> </td>
<td width="192"> </td>
<td> </td>
<td width="192"> </td>
<td width="10"> </td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
";
}
}
elseif (!$id && $details) {
$result = mysql_query("SELECT * FROM photogallery WHERE details='$details'") or die(mysql_error());
$num_rows = mysql_num_rows($result);
while ($u = mysql_fetch_array($result)) {
extract($u);
//$f_price = number_format($price,2);
echo"<table width="798" height="400" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="300">$pic</td>
</tr>
<tr>
<td height="100">$description</td>
</tr>";
}
}
echo "</table>\n";
?>works...
toplet159
Forum Newbie
Posts: 10 Joined: Sun Jul 11, 2004 1:20 pm
Post
by toplet159 » Sun Jul 11, 2004 4:47 pm
wow thank you so much ive been trying for ages to do this