Forum Moderators: coopster

Message Too Old, No Replies

a href issue with mysql fetch array

         

scott815

7:22 pm on Sep 29, 2008 (gmt 0)

10+ Year Member



I am trying to make a the code below that works to show up inside a hyperlink for each listing. I tried wraping with a href but with no luck. I am new but trying to figure this out without any luck.

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo $row['Rows'] . " " .$row['field_rental_state_value']. " <br>";
}

grallis

7:55 pm on Sep 29, 2008 (gmt 0)

10+ Year Member



Hi scott815 -

Would help to see a bit more code, but I imagine you're trying to have the href in a link be dynamically populated with each id from a DB result set? In that case it would be -

while($row = mysql_fetch_assoc($result)){
echo "<a href=\"someScript.php?id=$row[id]\">$row[field_rental_state_value]</a> <br />";
}

Please verify this is what you need. Thanks

scott815

9:11 pm on Sep 29, 2008 (gmt 0)

10+ Year Member



while($row = mysql_fetch_assoc($result)){
echo "<a href=\"someScript.php?id=$row[id]\">$row['Rows'] . " " .$row['field_rental_state_value']</a> <br />";
}

trying something like this. Trying to put what I have in the first and link it to site links like this www.website.com/state/[field_rental_state_value]

PHP_Chimp

9:16 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




echo "<a href=\"someScript.php?id=$row[id]\">{$row['Rows']} {$row['field_rental_state_value']}</a> <br />";

Values from arrays need to have {}'s around them.

Give that a try and see how it works.

grallis

9:46 pm on Sep 29, 2008 (gmt 0)

10+ Year Member



Hi scott815 -

If you're going by this snippet of code you left


echo "<a href=\"someScript.php?id=$row[id]\">$row['Rows'] . " " .$row['field_rental_state_value']</a> <br />";

You'll need to jump out of your double quotes properly, and if you're not going to jump out of your double quotes, drop the single quotes around the array key, like one of these:

Jumping out to concatenate ...


echo "<a href=\"someScript.php?id=$row[id]\">" . $row['Rows'] . " " . $row['field_rental_state_value'] . "</a> <br />";

or this

Not jumping out ...


echo "<a href=\"someScript.php?id=$row[id]\">$row[Rows] $row[field_rental_state_value]</a> <br />";

g1smd

9:53 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I always sanitise the data when using it as a URL... remove spaces (convert word breaks to hyphens or periods), make all lower-case, remove other punctuation, etc, and repurpose it for the anchor text: retain spaces, Camel Case the words etc.

grallis

10:08 pm on Sep 29, 2008 (gmt 0)

10+ Year Member



Good call g1smd - I usually do it on the way in, unless it's all user-entered data, at which point i cleanse it on the way in, then take some precautionary measures on the way out.

g1smd

10:17 pm on Sep 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sure, "garbage in, garbage out" is the first rule of computers.