fantomel Posted March 6, 2009 Share Posted March 6, 2009 Hello i'm trying to get some data from mysql but i run into a problem and i don't know how to fix it please can someone help me ? function get_bottom_menu() { $query = "SELECT * FROM cms_pages WHERE active = 1 ORDER BY position"; $result = mysql_query($query); while($check = mysql_fetch_array($result)) { echo "<a href="index.php?page=" . $check['page_id'] . ">" . ['link_name'] "."</a>"; } } Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/ Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 And the problem is? Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778038 Share on other sites More sharing options...
fantomel Posted March 6, 2009 Author Share Posted March 6, 2009 And the problem is? sorry forget to post it Parse error: parse error, expecting `','' or `';'' in C:\wamp\www\config\config.php on line 31 Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778040 Share on other sites More sharing options...
DjMikeS Posted March 6, 2009 Share Posted March 6, 2009 Of course you get that error... echo "<a href="index.php?page=" . $check['page_id'] . ">" . ['link_name'] "."</a>"; What do you think is wrong with that ? Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778044 Share on other sites More sharing options...
fantomel Posted March 6, 2009 Author Share Posted March 6, 2009 Of course you get that error... echo "<a href="index.php?page=" . $check['page_id'] . ">" . ['link_name'] "."</a>"; What do you think is wrong with that ? ooops forget to add ... i've added $check but still same error Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778049 Share on other sites More sharing options...
DjMikeS Posted March 6, 2009 Share Posted March 6, 2009 What does the error mean ? That you have closed your argument, but failed to close the echo statement... Now where-o-where did I close that argument...hmm echo "<a href="index.php?page=" . $check['page_id'] . ">" . ['link_name'] "."</a>"; Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778054 Share on other sites More sharing options...
fantomel Posted March 6, 2009 Author Share Posted March 6, 2009 if i wold see the mistake i think i could remove it but i can't see it cuz i'm running out of time around here and and moving to fast.. doing multiple things in the same time.. Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778059 Share on other sites More sharing options...
DjMikeS Posted March 6, 2009 Share Posted March 6, 2009 The error is so obvious... Just review the double qoutes in your echo statement... Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778064 Share on other sites More sharing options...
fantomel Posted March 6, 2009 Author Share Posted March 6, 2009 echo "<a href=index.php?page=" . $check['page_id'] . ">" . $check['link_name'] . "</a>"; is it ok like this ? didn't had time to test it:-s. Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778068 Share on other sites More sharing options...
Mchl Posted March 6, 2009 Share Posted March 6, 2009 Not really. It will generate invalid HTML. Try echo "<a href='index.php?page={$check['page_id']}'>{$check['link_name']}</a>"; Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778069 Share on other sites More sharing options...
fantomel Posted March 6, 2009 Author Share Posted March 6, 2009 it doesn't make the echo on the page.. i used get_bottom_menu(); in the place where i want to generate it. Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778073 Share on other sites More sharing options...
DjMikeS Posted March 6, 2009 Share Posted March 6, 2009 You're getting close... Your php is well formed, but you HTML is not... http://www.w3schools.com/HTML/html_links.asp You solve it in three ways: 1. escape the needed double qoutes inside your argument: echo "<a href=\"index.php?page=" . $check['page_id'] . "\">" . $check['link_name'] "."</a>"; 2. use single qoutes for your html: echo "<a href='index.php?page=" . $check['page_id'] . "'>" . $check['link_name'] "."</a>"; 3. use single qoutes for your echo statement: echo '<a href="index.php?page=' . $check['page_id'] . '>' . $check['link_name'] '.'</a>'; At last: you may use variables in echo statements. So probably the best would be: echo "<a href=\"index.php?page=$check['page_id']\">$check['link_name']</a>"; Which should run fine... Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778076 Share on other sites More sharing options...
fantomel Posted March 6, 2009 Author Share Posted March 6, 2009 Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\config\config.php on line 31 for echo "<a href=\"index.php?page=$check['page_id']\">$check['link_name']</a>"; and for the rest it gives the same error.. from the beginning. Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778081 Share on other sites More sharing options...
DjMikeS Posted March 6, 2009 Share Posted March 6, 2009 Try the curly brackets as Mchl mentioned.... Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778083 Share on other sites More sharing options...
fantomel Posted March 6, 2009 Author Share Posted March 6, 2009 i've already did that.. on var_dump works it's getting the data from sql the problem is from the echo statement . Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778086 Share on other sites More sharing options...
DjMikeS Posted March 6, 2009 Share Posted March 6, 2009 Are you sure that this echo statement is on line 31? Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778096 Share on other sites More sharing options...
fantomel Posted March 6, 2009 Author Share Posted March 6, 2009 Yes i'm sure.. but i've solved the problem.. made the code without function i placed it where i wanted. Link to comment https://forums.phpfreaks.com/topic/148218-solved-getting-data-from-mysql/#findComment-778129 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.