edanlee Posted April 14, 2008 Share Posted April 14, 2008 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 Quote Link to comment Share on other sites More sharing options...
AP81 Posted April 14, 2008 Share Posted April 14, 2008 Can you clarify what exactly you want to do here? Your question is vague. Quote Link to comment Share on other sites More sharing options...
edanlee Posted April 14, 2008 Author Share Posted April 14, 2008 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 Quote Link to comment Share on other sites More sharing options...
Pioden Posted April 14, 2008 Share Posted April 14, 2008 First off you need to change the name of 'order'. Its a reserved word for MySQL and can lead to all sorts of chaos!!! H Quote Link to comment Share on other sites More sharing options...
edanlee Posted April 14, 2008 Author Share Posted April 14, 2008 ok i can do that... although it is working... but can you tell me how to link my results to the link thats i have stored in with the video in mysql Quote Link to comment Share on other sites More sharing options...
edanlee Posted April 15, 2008 Author Share Posted April 15, 2008 can anyone please help me with this??? the answer is still unanswered. much thanks, Edanlee Quote Link to comment Share on other sites More sharing options...
Pioden Posted April 16, 2008 Share Posted April 16, 2008 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 Quote Link to comment Share on other sites More sharing options...
edanlee Posted April 16, 2008 Author Share Posted April 16, 2008 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. Quote Link to comment Share on other sites More sharing options...
Pioden Posted April 16, 2008 Share Posted April 16, 2008 Sorry about the mistake in the code - I'd just got out of bed !! 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.