|
Posted by Richard Lynch on 05/12/05 09:39
On Wed, May 11, 2005 10:19 pm, Mark Sargent said:
> I'll try this differently(I hope). With the below code, variables are
> named/set twice ($db, $num, $result, $myrow) etc. In ASP, from what I
> remember, that would be a no no. Currently, this code only populates the
I don't think ASP would issue an error if you re-used a variable...
In fact, I can almost guarantee I re-used variables all the time in ASP.
There might have been some kind of Programming Guidelines where you worked
that said not to do that, though...
> 1st select box. Coupla Qs. Do I have to connect to the db again, in the
> second block of code..? Should the variables in the 2nd block of code,
> be named differently to the 1st block.? In ASP the query variables would
> be named uniquely, identifying to each query like so, prod_query_num,
> prod_query_result and so forth. I must admit, my recollection of ASP is
> very vague. Anyway, I hope this explains what I'm looking to understand.
> Cheers.
>
> Mark Sargent.
>
> <html>
> <body>
> <hr>
> <h1 align=center>JUMBO STATUS</h1><p>
> <center>Used Hardware Specialist</center>
> <hr>
> <h2 align=center>Admin</h2>
> <table align="center" border="2">
> <tr>
> <td><h3 align=center>PRODUCT TYPE</h3></td>
> </tr>
> <tr><td><center>
> <select name="poduct_type">
> <?php
> $db = mysql_connect("localhost", "root", "grunger");
> mysql_select_db("status",$db);
> $result = mysql_query("SELECT ProductTypes.product_type_detail,
> ProductTypes.product_type_id FROM ProductTypes",$db);
> $num = mysql_num_rows($result);
I would move all of this stuff OUTSIDE the <select> because after you add
your error messages, you'll never see them if they are inside the
<select>.
> for ($i=0; $i<$num; $i++){
> $myrow=mysql_fetch_array($result);
> $product_type=mysql_result($result,$i,"product_type_detail");
> $product_type_id=mysql_result($result,$i,"product_type_id");
> $maker=mysql_result($result,$i,"maker_detail");
> $maker_id=mysql_result($result,$i,"maker_id");
> echo "<option value=\"$product_type_id\">$product_type</option><br>";
You are not using maker, nor maker_id, so why put them in the query, and
why get them from your result set?
> }
> ?>
> </select>
> </center>
> </td></tr>
> </table>
> <table align="center" border="2">
> <tr>
> <td><h3 align=center>Maker</h3></td>
> </tr>
> <tr><td><center>
> <select name="slect_maker">
> <?php
> $db = mysql_connect("localhost", "root", "grunger");
Don't connect to the database twice.
That's the most expensive (time-wise) thing in your whole script, probably.
> mysql_select_db("status",$db);
And you don't need this either.
> $result = mysql_query("SELECT Makers.maker_id Makers.maker_detail FROM
> Makers",$db);
> $num = mysql_num_rows($result);
Again, move these outside the <select>
> for ($i=0; $i<$num; $i++){
> $myrow=mysql_fetch_array($result);
> $maker=mysql_result($result,$i,"maker_detail");
> $maker_id=mysql_result($result,$i,"maker_id");
> echo "<option value=\"$maker_id\">$maker</option><br>";
> }
> ?>
> </select>
> </center>
> </td></tr>
> </table>
> <p>
> <p>
> <p>
> <hr><center>email: ???????????<p>
> Telephone:????????<p>
> Fax: ?????????
> </center>
> <hr>
> </body>
> </html>
--
Like Music?
http://l-i-e.com/artists.htm
[Back to original message]
|