Page 1 of 1

cant select from different tables when switching pages

Posted: Sun Jul 11, 2004 1:20 pm
by toplet159
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">&nbsp;</td>
                <td width="192" align="center" valign="middle" background="$pic1"><img src="camera.jpg" width="190" height="190"></td>
                <td width="10">&nbsp;</td>
                <td width="192"align="center" valign="middle" background="$pic2"><img src="camera.jpg" width="192" height="192"></td>
                <td width="10">&nbsp;</td>
                <td width="192" align="center" valign="middle" background="$pic3"><img src="picbg.gif" width="192" height="192"></td>
                <td width="10">&nbsp;</td>
                <td width="192" align="center" valign="middle" background="$pic4"><img src="picbg.gif" width="192" height="192"></td>
                <td width="10">&nbsp;</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">&nbsp;</td>
                        <td width="192" align="center" valign="middle" background="textbg.gif"><a href="events6.php?details=$details">Click for more Information</a></td>
                        <td>&nbsp;</td>
                        <td width="192" align="center" valign="middle" background="textbg1.gif">Lovely
                          Camera</td>
                        <td>&nbsp;</td>
                        <td width="192">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td width="192">&nbsp;</td>
                        <td width="10">&nbsp;</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";
?>

Posted: Sun Jul 11, 2004 1:28 pm
by feyd
do you have register_globals on? look through the following's output to find out:

Code: Select all

<?php

phpinfo();

?>

Posted: Sun Jul 11, 2004 3:24 pm
by toplet159
im not sure if they're on
im using lycos.co.uk free web hosting
http://members.lycos.co.uk/tarrison159/ ... lobals.php
thats what i got when i typed in that thing
hope this helps

Posted: Sun Jul 11, 2004 3:28 pm
by feyd
yep.. register_globals is on..

Posted: Sun Jul 11, 2004 3:36 pm
by toplet159
so no idea how to get it to work?

Posted: Sun Jul 11, 2004 3:36 pm
by feyd
from what I can tell without running it, it looks like it'd work.

Posted: Sun Jul 11, 2004 3:41 pm
by toplet159
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=

Posted: Sun Jul 11, 2004 3:55 pm
by feyd
post the table structures and some data from each..

moving topic to Databases

Posted: Sun Jul 11, 2004 3:59 pm
by toplet159

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

Code: Select all

tag[/color]

Posted: Sun Jul 11, 2004 4:20 pm
by feyd
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'

Posted: Sun Jul 11, 2004 4:35 pm
by toplet159
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"; 
?>

?>

Posted: Sun Jul 11, 2004 4:43 pm
by feyd

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

Posted: Sun Jul 11, 2004 4:47 pm
by toplet159
wow thank you so much ive been trying for ages to do this :)