Jump to content

Displaying data and url


edanlee

Recommended Posts

i have a database setup with rows that consist of these values. 'id', 'order', 'name', 'details',  'url', 'catagory'.     

i have set up a table in php with 4 catagory's. and i am displaying the rows based on catagory...

everything is working but what i want to do is have the results linked by whats in the 'url' row. here is my code for displaying my content.

$query  = "SELECT `name` FROM `videos` WHERE `catagory` = CONVERT(_utf8 'Overview' USING latin1) COLLATE latin1_swedish_ci ORDER BY `order` ASC";
$result = mysql_query($query);

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

 

how would i be able to link what is echo'd by whats stored in that rows url section...

 

thank you,

Edanlee

Link to comment
Share on other sites

ok.. i have a list of videos that will be all pulled from mysql. everyone of those videos will be linked to its url... so for instance... say i have 5 videos on the page that are pulled from mysql... overview, programs needed, shading, texturing. well in mysql each entry has a url section so that i can store each movies url in it. so if i click on one of the movies i want it to go to the url that i have specified in the url field in mysql. i hope this clarifys some...

 

edanlee

Link to comment
Share on other sites

Something like this?

 

$sql = "SELECT `name`,'url' FROM `videos` WHERE `catagory` = CONVERT(_utf8 'Overview' USING latin1) COLLATE latin1_swedish_ci ORDER BY `order` ASC";

 

$result = @mysql_query($sql,$connection) or die("Couldn't execute query.". $php_errormsg . mysql_error());

 

while ($row = mysql_fetch_array($result)) {

        $name = $row['name'];

        $url = $row['url'];

 

$display .= "<a href=\"$url\">$name</a><br />";

 

echo "$display";

}

 

As you can see I write my code in a more 'longhand' way than most - I find it helps code maintenance.

 

HTH

 

Huw

Link to comment
Share on other sites

Thank you... that works... I shoulda thought to use a while statement... anyways i did have to alter 2 things in your code...

$display .= "<a href=\"$url\">$name[/url]";

was changed to:

$display .= "<a href=\"$url\">$name</a>";

 

and i didnt have a $connection

so i changed the code to:

$result = mysql_query($sql) or die("Couldn't execute query.". $php_errormsg . mysql_error());

well i did but not like this and it was connecting else where.

 

but thank you for responding i was pounding my head on the table for days trying to figure this out....

 

Edanlee

 

And btw... you should use code block... makes it alot easier to read and grab.

Link to comment
Share on other sites

Sorry about the mistake in the code - I'd just got out of bed !!  ;D

 

And btw... you should use code block... makes it alot easier to read and grab.

 

I've tried - and I really don't get on with it. I taught myself to code from books and the 'longhand' way appealed to me more. I also like the way it keeps the PHP and XHTML seperate - PHP at the top and display code after. Horses for courses I guess.

 

BTW is it working now?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.