Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
will83
Forum Commoner
Posts: 53 Joined: Thu Nov 10, 2005 3:13 pm
Post
by will83 » Fri Jan 13, 2006 12:08 pm
Hi there,
The first while loop is working fine, however the second one does not work.
Can anyone see a problem??
Code: Select all
$query = "SELECT * from company_ins, company_log WHERE company_ins.ins_id = '$typeid'
AND company_log.Id = company_ins.company_Id order by company_log.name";
$result = mysql_query($query, $conn);
//check for any featured providers
while ($row = mysql_fetch_array($result, $conn)) {
if ($row['type_featured'] == "f") {
?>
<div class="linkbox">
FEATURED<a href="<?php echo $row['link']; ?>" class="link" target="_blank"><strong><?php echo $row['name']; ?></strong></a>
<p><?php echo $row['description']; ?><p><a href="<?php echo $row['link']; ?>" target="_blank"><?php echo $row['link']; ?></a></p>
</div>
<?php
}
}
while ($row = mysql_fetch_array($result, $conn)) {
if ($row['type_featured'] !='f') {
?>
<div class="linkbox">
<a href="<?php echo $row['link']; ?>" class="link" target="_blank"><strong><?php echo $row['name']; ?></strong></a>
<p><?php echo $row['description']; ?><p><a href="<?php echo $row['link']; ?>" target="_blank"><?php echo $row['link']; ?></a></p>
</div>
<?php
}
}
?>
Any ideas would be great, thanks
Will
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Fri Jan 13, 2006 12:33 pm
How about comparing for type_featured inside of one while loop?
Code: Select all
$query = "SELECT *
FROM company_ins, company_log
WHERE company_ins.ins_id = '$typeid'
AND company_log.Id = company_ins.company_Id
ORDER BY company_log.name";
$result = mysql_query($query, $conn);
//check for any featured providers
while ($row = mysql_fetch_array($result, $conn)) {
if ($row['type_featured'] == "f") {
?>
<div class="linkbox">
FEATURED<a href="<?php echo $row['link']; ?>" class="link" target="_blank"><strong><?php echo $row['name']; ?></strong></a>
<p><?php echo $row['description']; ?><p><a href="<?php echo $row['link']; ?>" target="_blank"><?php echo $row['link']; ?></a></p>
</div>
<?php
}
else
{
?>
<div class="linkbox">
<a href="<?php echo $row['link']; ?>" class="link" target="_blank"><strong><?php echo $row['name']; ?></strong></a>
<p><?php echo $row['description']; ?><p><a href="<?php echo $row['link']; ?>" target="_blank"><?php echo $row['link']; ?></a></p>
</div>
<?php
}
}
?>
will83
Forum Commoner
Posts: 53 Joined: Thu Nov 10, 2005 3:13 pm
Post
by will83 » Sat Jan 14, 2006 5:27 am
Yeh, I was thinking how I could get round that, but all the type_featured entries have to be printed first you see.
Thanks for the suggestion anyway.
Will
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Sat Jan 14, 2006 8:01 am
Please check
here for mysql_fetch_array() syntax
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Sat Jan 14, 2006 1:05 pm
will83 wrote: Yeh, I was thinking how I could get round that, but all the type_featured entries have to be printed first you see.
What do you mean "printed"? Do mean sent to the browser? That is easy enough to do using an intermediate step like reading $row into a new array and capturing the 'type_featured' value into a var using your while loop.
Bill H
DevNet Resident
Posts: 1136 Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:
Post
by Bill H » Sun Jan 15, 2006 9:26 am
In order to pass through the array a second time you must set the pointer back to the beginning