?
Solved

easy way to duplicate this script

Posted on 2003-03-26
14
Medium Priority
?
166 Views
Last Modified: 2006-11-17
I have this script it works fine but what I want to do is request more than 1 result from the querystring.
 
see this will request the querystring of subid=* (in this case 114)
like this
http://www.earthquip.com.au/product.php?subid=114
(this works click it to see the results)

but what i want to do is display what is on that page http://www.earthquip.com.au/product.php?subid=114 then after it display records for subid 115 it will display 116 and so on whatever is in the querystring

like this
http://www.earthquip.com.au/product.php?subid=114&115&116   ****this part subid=114&115&116  

can anyone help with this.

if i had more points i would award them to you (if i had a credit card i would purchase more points)

thanks in advance

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?
$conn = mysql_connect("localhost", "earthquip67", "transdb793") or
die ("Could Not connect to Database");

$db = mysql_select_db("transdat_com_au", $conn) or
die ("Could Not select db");
?>
<?
##$query = "SELECT DISTINCT cat_id FROM machines";
$query = "SELECT DISTINCT machines.*  FROM machines WHERE machines.subcat_id = $subid AND machines.supp_id = '1008' ";
$query2 = "SELECT DISTINCT machines.*, makes2.* FROM machines, makes2 WHERE machines.subcat_id = $subid AND machines.make_id = makes2.id AND machines.supp_id = '1008' ";
$query3 = "SELECT machines.subcat_id, machines.supp_id, subcat2.* FROM machines, subcat2 WHERE machines.subcat_id = subcat2.id AND machines.subcat_id = $subid AND machines.supp_id = '1008'";

##$query = "SELECT DISTINCT machines.cat_id, subcat2.name FROM machines, subcat2 WHERE machines.cat_id = subcat2.id AND cat_id = $subcatid";
##$query = "SELECT * FROM machines WHERE id = $id ";
$result = mysql_query($query) or die("Query failed");
$result2 = mysql_query($query2) or die("Query failed");
$result3 = mysql_query($query3) or die("Query failed");
$line3 = mysql_fetch_array($result3, MYSQL_ASSOC);
?>
<html>
<head>
<title>Earthquip - Product</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../style.css" rel="stylesheet" type="text/css">
<link href="../master.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr>
    <td width="130" align="left" valign="top">
      <? include 'left.htm';?>
    </td>
    <td height="100%" align="left" valign="top" bgcolor="#CCCC99">
      <? include 'top.htm';?>
      <table width="80%" border="0" cellspacing="0" cellpadding="0" height="100%">
        <tr>
          <td height="23" colspan="2" align="left" valign="top" bgcolor="#000000">&nbsp;</td>
        </tr>
        <tr>
          <td width="13%" height="100%" align="left" valign="top" bgcolor="#FFFFFF">&nbsp;</td>
          <td width="87%" height="100%" align="left" valign="top" bgcolor="#FFFFFF">
            <p class="head"><br>
              List of Products for Equipment <? print $line3["name"]; ?></p>
            <?

   /* Printing results in HTML */
   print "<table width=100% border=0 cellpadding=3 cellspacing=3>\n";
   print "<tr>\n";
   print "<td width=10% align=left valign=top>ID </td>\n";
   print "<td width=15 align=left valign=top>&nbsp;</td>\n";
   print "<td width=10% align=left valign=top>Make</td>\n";
   print "<td width=10% align=left valign=top>Model</td>\n";
   print "<td width=10% align=left valign=top>Year</td>\n";
   print "<td width=20% align=left valign=top>Serial #</td>\n";
   print "<td width=10% align=left valign=top>Capacity</td>\n";
   print "<td width=15% align=left valign=top>Price</td>\n";
   print "<td width=10% align=left valign=top>Stock #</td>\n";
   print " </tr>\n";
   while (($line2 = mysql_fetch_array($result2, MYSQL_ASSOC)) && ($line = mysql_fetch_array($result, MYSQL_ASSOC)))
   ##while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
    {
         print "\t<tr>\n";
       print "\t\t<td width=10% align=left valign=top><a href=\"productdescription.php?id=" . $line["id"] . "\">" . $line["id"] . "</a></td>\n";
       print "\t\t<td width=5% align=left valign=top><a href=\"productdescription.php?id=" . $line["id"] . "\"><img src=../photo.gif width=15 height=15 border=0 ></a></td>\n";
         print "\t\t<td width=10% align=left valign=top>" . $line2["name"] . "</td>\n";
       print "\t\t<td width=10% align=left valign=top>" . $line["model"] . "</td>\n";
         print "\t\t<td width=10% align=left valign=top>" . $line["year"] . "</td>\n";
       print "\t\t<td width=20% align=left valign=top><a href=\"proddescription.php?id=" . $line["id"] . "\">" . $line["serial"] . "</a></td>\n";
         print "\t\t<td width=10% align=left valign=top>" . $line["capacity"] . "</td>\n";
       print "\t\t<td width=15% align=left valign=top>" . $line["price"] . "</td>\n";
       print "\t\t<td width=10% align=left valign=top>" . $line["stock_number"] . "</td>\n";
         print "\t</tr>\n";
   }
   print "</table>\n";

   /* Free resultset */
   mysql_free_result($result);
   mysql_free_result($result2);

   /* Closing connection */
   mysql_close($link);
    ?>
          </td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
0
Comment
Question by:abulink
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
14 Comments
 
LVL 15

Accepted Solution

by:
VGR earned 600 total points
ID: 8216420
arf
1) I shouldn't help, you war-prone aussie , U.S.Agression vallet 8-)  (hu hu hu :D )

2) you are using register_globals=On in your php.ini, it's very good. You escape a lot of undue complications

3) Easy problem.
Let's suppose you would like this call
http://www.earthquip.com.au/product.php?subid=114&115&116 

First modify it this way :
http://www.earthquip.com.au/product.php?subid=114_115_116 

use underscore or whatever "URI-neutral" character you want (forbidden ones are ? and & , slashes - both ways - are not a very good idea ; I suggest to stick with the underscore )

4) note also that the first line "<!DOCTYPE" begins the output, so you'll hve problems issuing headers afterwards (like "Location: " or "Refresh: " )

5) now It's my time to work. Look at this modified script (I didn't test it)(it's not the only solution)

<?
$conn = mysql_connect("localhost", "earthquip67", "transdb793") or
die ("Could Not connect to Database");

$db = mysql_select_db("transdat_com_au", $conn) or
die ("Could Not select db");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Earthquip - Product</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="../style.css" rel="stylesheet" type="text/css">
<link href="../master.css" rel="stylesheet" type="text/css">
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" align="left" cellpadding="0" cellspacing="0">
 <tr>
   <td width="130" align="left" valign="top">
     <? include 'left.htm';?>
   </td>
   <td height="100%" align="left" valign="top" bgcolor="#CCCC99">
     <? include 'top.htm';?>
<?
// FIRST analyze the request
$idstoprocess=explode('_',$subid);
// now loop
foreach($idtoprocess as $value) { // standard below (modified variable name only)
##$query = "SELECT DISTINCT cat_id FROM machines";
$query = "SELECT DISTINCT machines.*  FROM machines WHERE machines.subcat_id = $value AND machines.supp_id = '1008' ";
$query2 = "SELECT DISTINCT machines.*, makes2.* FROM machines, makes2 WHERE machines.subcat_id = $value AND machines.make_id = makes2.id AND machines.supp_id = '1008' ";
$query3 = "SELECT machines.subcat_id, machines.supp_id, subcat2.* FROM machines, subcat2 WHERE machines.subcat_id = subcat2.id AND machines.subcat_id = $value AND machines.supp_id = '1008'";

##$query = "SELECT DISTINCT machines.cat_id, subcat2.name FROM machines, subcat2 WHERE machines.cat_id = subcat2.id AND cat_id = $subcatid";
##$query = "SELECT * FROM machines WHERE id = $id ";
$result = mysql_query($query) or die("Query failed");
$result2 = mysql_query($query2) or die("Query failed");
$result3 = mysql_query($query3) or die("Query failed");
$line3 = mysql_fetch_array($result3, MYSQL_ASSOC);
?>
     <table width="80%" border="0" cellspacing="0" cellpadding="0" height="100%">
       <tr>
         <td height="23" colspan="2" align="left" valign="top" bgcolor="#000000">&nbsp;</td>
       </tr>
       <tr>
         <td width="13%" height="100%" align="left" valign="top" bgcolor="#FFFFFF">&nbsp;</td>
         <td width="87%" height="100%" align="left" valign="top" bgcolor="#FFFFFF">
           <p class="head"><br>
             List of Products for Equipment <? print $line3["name"]; ?></p>
           <?

  /* Printing results in HTML */
  print "<table width=100% border=0 cellpadding=3 cellspacing=3>\n";
  print "<tr>\n";
  print "<td width=10% align=left valign=top>ID </td>\n";
  print "<td width=15 align=left valign=top>&nbsp;</td>\n";
  print "<td width=10% align=left valign=top>Make</td>\n";
  print "<td width=10% align=left valign=top>Model</td>\n";
  print "<td width=10% align=left valign=top>Year</td>\n";
  print "<td width=20% align=left valign=top>Serial #</td>\n";
  print "<td width=10% align=left valign=top>Capacity</td>\n";
  print "<td width=15% align=left valign=top>Price</td>\n";
  print "<td width=10% align=left valign=top>Stock #</td>\n";
  print " </tr>\n";
  while (($line2 = mysql_fetch_array($result2, MYSQL_ASSOC)) && ($line = mysql_fetch_array($result, MYSQL_ASSOC)))
  ##while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
   {
        print "\t<tr>\n";
      print "\t\t<td width=10% align=left valign=top><a href=\"productdescription.php?id=" . $line["id"] . "\">" . $line["id"] . "</a></td>\n";
      print "\t\t<td width=5% align=left valign=top><a href=\"productdescription.php?id=" . $line["id"] . "\"><img src=../photo.gif width=15 height=15 border=0 ></a></td>\n";
        print "\t\t<td width=10% align=left valign=top>" . $line2["name"] . "</td>\n";
      print "\t\t<td width=10% align=left valign=top>" . $line["model"] . "</td>\n";
        print "\t\t<td width=10% align=left valign=top>" . $line["year"] . "</td>\n";
      print "\t\t<td width=20% align=left valign=top><a href=\"proddescription.php?id=" . $line["id"] . "\">" . $line["serial"] . "</a></td>\n";
        print "\t\t<td width=10% align=left valign=top>" . $line["capacity"] . "</td>\n";
      print "\t\t<td width=15% align=left valign=top>" . $line["price"] . "</td>\n";
      print "\t\t<td width=10% align=left valign=top>" . $line["stock_number"] . "</td>\n";
        print "\t</tr>\n";
  }
  print "</table>\n";

  /* Free resultset */
  mysql_free_result($result);
  mysql_free_result($result2);

  /* Closing connection */
  mysql_close($link);
   ?>
         </td>
       </tr>
     </table></td>
 </tr>
</table>
<?
} // foreach (one table per subid found)
?>
</body>
</html>
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8218191
Start with using an HTML select which allows multiple selects. Call the select something[]. NOTE the []. This will give you all the selections in an array. Without [] you will only get 1 entry, even if many are chosen.

You can then use ...

$if (isset($_GET['something']))
 {
 $sWhereClause = 'WHERE ';
 foreach($_GET['something'] as $k => $v)

 }
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 8218218
Start with using an HTML select which allows multiple selects. Call the select something[]. NOTE the []. This will give you all the selections in an array. Without [] you will only get 1 entry, even if many are chosen.

You can then use ...

$if (isset($_GET['something']))
 {
 $sWhereClause = 'WHERE ';
 foreach($_GET['something'] as $k => $v)
  {
  $sWhere .= "subcatid = '$v' OR ";
  }
 $sWhere = rtrim($sWhere,' OR');
 }

and then you have your WHERE clause for the SQL.

Richard.
0
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 
LVL 15

Expert Comment

by:VGR
ID: 8218400
well, it's an other bit of the same solution ;-)
0
 

Author Comment

by:abulink
ID: 8220605
ill try it when i get to work in about 1hr from time of posting..

cheers abu.

0
 
LVL 15

Expert Comment

by:VGR
ID: 8220683
I suggest you try first my slight modification of your script [it may contain typos, but you can tets it from the tets URL you provided], then only change the FORM (first page) following Richard's advice, to ease the transmission of the array. (should we serialize() it ?)
0
 

Author Comment

by:abulink
ID: 8221088
i tried you modification

http://www.earthquip.com.au/product1a.php?subid=114_115

but nothing comes up

dosent display anything.
0
 

Author Comment

by:abulink
ID: 8221170
ok i found it. you had a typo in this statement
foreach($idstoprocess as $value)

was

foreach($idtoprocess as $value)

it works now for 1 subid eg.
http://www.earthquip.com.au/product.php?subid=117

but when you have 2
http://www.earthquip.com.au/product.php?subid=117_118

it comes up with
Query failed
0
 
LVL 15

Expert Comment

by:VGR
ID: 8221181
of course....

nothing, no error no display... It's well known, each time I modify a script, it suddenly doesn't display anything any more !

espacially if it begins with

<?
$conn = mysql_connect("localhost", "earthquip67", "transdb793") or
die ("Could Not connect to Database");

$db = mysql_select_db("transdat_com_au", $conn) or
die ("Could Not select db");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
[other HTML stuff]

so logically it should either DIE with a message, or at least start the HTML output. So something should be visible. (or at least present in the source code of the page)

Don't you agree ?
0
 

Author Comment

by:abulink
ID: 8221219
Woops my mistake sorry

it does work for 1 subid but when you have 2 it dosent show the second

it works now for 1 subid eg.
http://www.earthquip.com.au/product1a.php?subid=117

but when you have 2
http://www.earthquip.com.au/product1a.php?subid=117_118

it only shows the first record set for the 1st sub id, in the above case record 117
0
 
LVL 15

Expert Comment

by:VGR
ID: 8221240
well, I thought this was enough to start a for each loop :

$idstoprocess=explode('_',$subid);
foreach($idtoprocess as $value) {


but may-be I'm wrong, I normally don't use foreach ;-)

I would normally have written (and this would have worked right out I think)

$idstoprocess=explode('_',$subid);
for ($i=0;$i<count($idstoprocess);$i++) {
  $value=$idstoprocess[$i];
  // rest unchanged
0
 

Author Comment

by:abulink
ID: 8221246
ok it works now just had to reorder the loop code. So that it loops the code after the table tags.

thank you very much.
your help was greatly appreciated
0
 

Author Comment

by:abulink
ID: 8221259
Thanks mate.  You saved me heaps of time.
sorry for the small amount of points .I would award you more points if i had any.

cheers aron
0
 
LVL 15

Expert Comment

by:VGR
ID: 8221293
no problem.
I HATE foreach ;-)
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

770 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