Newbie question: MySQL, PHP with <a href>+$QUERY_STRING

This is a discussion on Newbie question: MySQL, PHP with <a href>+$QUERY_STRING within the PHP General forums, part of the PHP Programming Forums category; Hi, I'm quite a newbie to PHP and MySQL. I'ld like to list a MySQL table with PHP ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-10-2004
Szabolcs J. Csorge
 
Posts: n/a
Default Newbie question: MySQL, PHP with <a href>+$QUERY_STRING

Hi,


I'm quite a newbie to PHP and MySQL. I'ld like to list a MySQL table
with PHP to a table on my webpage and then add hyperlinks to every
element. It works fine with simple hyperlinks but I'ld like to add a
$QUERY_STRING to my hyperlinks, and this string should be the contents
of the MySQL cell that the listed rows contain.

So, in theory, I've got a db row like this:

id | product | type
----------------------
1 | magazine | softcover
2 | book | softcover

and so on. I'ld like to do this as a result:

<a href="testcode.php?1">Magazine</a> and so on...


For this, I made the following code:

$query = "SELECT product FROM prods WHERE type = '$QUERY_STRING' ORDER
BY id";

$result = mysql_query($query) or die("Query failed : " .
mysql_error());
$numrows = mysql_num_rows ( $result);

function identify ($ident)
{
$ident = mysql_query ("SELECT id FROM prods") or die("Query failed : "
.. mysql_error());
$ident2 = mysql_fetch_array($ident);
$ident = $ident2["id"];
//return $ident;
}

print "We have $numrows rows in the table.<P>";

print "<table width=\"100%\" border=0 cellspacing=\"0\"
cellpadding=\"0\">\n";
while ( $one_line = mysql_fetch_row( $result) )
{
print "<tr>\n";
foreach ( $one_line as $cell )
$ident = identify();
print "\t<td width=\"25%\" height=\"40\" valign=\"top\"><div
align=\"justify\"><font size=\"2\" face=\"Arial, Helvetica,
sans-serif\"><a href=\"testcode.php?$ident\">$cell</a></font></div></td>\n";
print "</tr>\n";
}
print "</table>\n";

mysql_close($link); ?>


I think I can handle the problem with creating the function
identify(), but have problems where to put it and how to use it. It is
possible that the solution is quite obvious but I can't figure it out.


Can anyone please help me with this? Please send a copy to
szabolcs@mediastar.hu as well.


Thanks a lot:


Szabolcs J. Csorge,
szabolcs@mediastar.hu

Budapest, Hungary
Reply With Quote
  #2 (permalink)  
Old 06-11-2004
Alekc
 
Posts: n/a
Default Re: Newbie question: MySQL, PHP with <a href>+$QUERY_STRING

What about this one?

<?

$query = "SELECT * FROM prods WHERE type = '$QUERY_STRING' ORDER BY id";

$result = mysql_query($query) or die("Query failed : " .
mysql_error());
$numrows = mysql_num_rows ( $result);

print "We have $numrows rows in the table.<P>";

print "<table width=\"100%\" border=0 cellspacing=\"0\"
cellpadding=\"0\">\n";
while ( $one_line = mysql_fetch_array( $result) )
{
print (<<<EOF
<td width="25%" height="40" valign="top">
<div align="justify">
<font size="2" face="Arial, Helvetica,sans-serif">
<a href="testcode.php?id={$one_line['id']}">{$one_line['product']}</a>
</font>
</div>
</td>
EOF
);
}
print "</table>\n";
mysql_close($link); ?>
?>

Alekc (al3kc at yah00 dot it)

szabolcs@mediastar.hu (Szabolcs J. Csorge) wrote in message news:<60881450.0406101034.5ad6adb4@posting.google. com>...
> Hi,
>
>
> I'm quite a newbie to PHP and MySQL. I'ld like to list a MySQL table
> with PHP to a table on my webpage and then add hyperlinks to every
> element. It works fine with simple hyperlinks but I'ld like to add a
> $QUERY_STRING to my hyperlinks, and this string should be the contents
> of the MySQL cell that the listed rows contain.
>
> So, in theory, I've got a db row like this:
>
> id | product | type
> ----------------------
> 1 | magazine | softcover
> 2 | book | softcover
>
> and so on. I'ld like to do this as a result:
>
> <a href="testcode.php?1">Magazine</a> and so on...
>
>
> For this, I made the following code:
>
> $query = "SELECT product FROM prods WHERE type = '$QUERY_STRING' ORDER
> BY id";
>
> $result = mysql_query($query) or die("Query failed : " .
> mysql_error());
> $numrows = mysql_num_rows ( $result);
>
> function identify ($ident)
> {
> $ident = mysql_query ("SELECT id FROM prods") or die("Query failed : "
> . mysql_error());
> $ident2 = mysql_fetch_array($ident);
> $ident = $ident2["id"];
> //return $ident;
> }
>
> print "We have $numrows rows in the table.<P>";
>
> print "<table width=\"100%\" border=0 cellspacing=\"0\"
> cellpadding=\"0\">\n";
> while ( $one_line = mysql_fetch_row( $result) )
> {
> print "<tr>\n";
> foreach ( $one_line as $cell )
> $ident = identify();
> print "\t<td width=\"25%\" height=\"40\" valign=\"top\"><div
> align=\"justify\"><font size=\"2\" face=\"Arial, Helvetica,
> sans-serif\"><a href=\"testcode.php?$ident\">$cell</a></font></div></td>\n";
> print "</tr>\n";
> }
> print "</table>\n";
>
> mysql_close($link); ?>
>
>
> I think I can handle the problem with creating the function
> identify(), but have problems where to put it and how to use it. It is
> possible that the solution is quite obvious but I can't figure it out.
>
>
> Can anyone please help me with this? Please send a copy to
> szabolcs@mediastar.hu as well.
>
>
> Thanks a lot:
>
>
> Szabolcs J. Csorge,
> szabolcs@mediastar.hu
>
> Budapest, Hungary

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:52 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0