Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help displaying data in a loop 1

Status
Not open for further replies.

Aeros

Programmer
Oct 7, 2002
166
US
Im kind of a php newbie here so this might be basic to some. I am able to display the 'categoryName' in the loop but I need to display the associated 'companyID' as well. Heres the query (built from dreamweaver MX)


QUERY
<?php
$catID_pullListing = &quot;1&quot;;
if (isset($HTTP_GET_VARS['textfield'])) {
$catID_pullListing = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['textfield'] : addslashes($HTTP_GET_VARS['textfield']);
}
mysql_select_db($database_MommynetSQL, $MommynetSQL);
$query_pullListing = sprintf(&quot;SELECT companyID, CompanyName FROM listonames WHERE Category = '$catID'&quot;, $catID_pullListing);
$pullListing = mysql_query($query_pullListing, $MommynetSQL) or die(mysql_error());
$row_pullListing = mysql_fetch_assoc($pullListing);
$totalRows_pullListing = mysql_num_rows($pullListing);

$colname_Recordset1 = &quot;1&quot;;
if (isset($HTTP_POST_VARS['1'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_POST_VARS['1'] : addslashes($HTTP_POST_VARS['1']);
}

$query_Recordset1 = sprintf(&quot;SELECT * FROM listonames WHERE `1` = '%s' ORDER BY `1` ASC&quot;, $colname_Recordset1);
?>


Heres the loop I am using that displays the 'CompanyName' field but wont display the 'companyID':

<?
while($CompanyName = mysql_fetch_row($pullListing)){
echo &quot;<A HREF=companyDetails.php?compID=$companyID>$CompanyName[1]</A><BR>&quot;;
}
?>
 
1. [tt]$query_pullListing = sprintf(&quot;SELECT companyID, CompanyName FROM listonames WHERE Category = '$catID'&quot;, $catID_pullListing);[/tt]
should probably read
[tt]$query_pullListing = sprintf(&quot;SELECT companyID, CompanyName FROM listonames WHERE Category = '%s'&quot;, $catID_pullListing);[/tt]
2. Why are you using [tt]sprintf[/tt] when PHP has a concatenation operator?
3. Where do you set [tt]$companyID[/tt]? I don't see it in your code. //Daniel
 
1. - Ill try that out
2. - I dont know...like I said, dreamweaver spit this code out.
3. - ? Im trying to display it in the output. It should be pulled from the query.
 
Ok, I see what you want to do now... Change this line:
[tt]while($CompanyName = mysql_fetch_row($pullListing)){[/tt]
to read
[tt]while(list($companyID, $companyName) = mysql_fetch_row($pullListing)){[/tt]
And then you would have to change this line:
[tt] echo &quot;<A HREF=companyDetails.php?compID=$companyID>$CompanyName[1]</A><BR>&quot;;[/tt]
to read
[tt] echo &quot;<A HREF=companyDetails.php?compID=$companyID>$companyName</A><BR>&quot;;[/tt] //Daniel
 
ahhh...you rule! That did it.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top