You are here: Re: [PHP] Inner Join or 2nd Query...? « PHP « IT news, forums, messages
Re: [PHP] Inner Join or 2nd Query...?

Posted by Mark Sargent on 05/12/05 10:00

Richard Lynch wrote:

>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...
>
>
Yep, I didn't make any sense there.

>
>
>>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>.
>
>
Ok, I'll do just that.

>
>
>
>>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?
>
>
Ah, forgot to remove them b4 posting, as they were there when I was
doing only 1 query.

>
>
>>}
>>?>
>></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.
>
>
Just the answer I wanted. thanx.

>
>
>>mysql_select_db("status",$db);
>>
>>
>
>And you don't need this either.
>
>
yep, that's obvious, now that I know you don't need the db connection a
2nd time too

>
>
>>$result = mysql_query("SELECT Makers.maker_id Makers.maker_detail FROM
>>Makers",$db);
>>$num = mysql_num_rows($result);
>>
>>
>
>Again, move these outside the <select>
>
>
Will do.

>
>
>>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>
>>
>>
>
>
>
But, you dind't comment on the 2nd query. Cheers.

Mark Sargent.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация