herghost Posted September 25, 2010 Share Posted September 25, 2010 Hi all, how would I write a string like this in an echo statement so the javascript runs? <a href="javascript:ajaxpage('test.php', 'content');">test</a> Quote Link to comment https://forums.phpfreaks.com/topic/214359-echo-help-include-java-string/ Share on other sites More sharing options...
dezkit Posted September 25, 2010 Share Posted September 25, 2010 echo "<a href=\"javascript:ajaxpage('test.php', 'content');\">test</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/214359-echo-help-include-java-string/#findComment-1115490 Share on other sites More sharing options...
herghost Posted September 25, 2010 Author Share Posted September 25, 2010 Thanks, I also would like to know how to display more than one row from my database, this is the query I have, but it only shows the 1st row, how would I make it show all rows? <?php $query = mysql_query("SELECT * FROM cats WHERE level='1' LIMIT 2"); if (!$query) { echo "Could not run query: " . mysql_error(); exit;} $row = mysql_fetch_row($query); { echo "<li><a href=\"javascript:ajaxpage('" . $row[1] . ".php', 'content');\">" . $row[1] . "</a></li>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/214359-echo-help-include-java-string/#findComment-1115499 Share on other sites More sharing options...
kenrbnsn Posted September 25, 2010 Share Posted September 25, 2010 You need to use a loop to fetch all the rows: <?phpwhile ($row = mysql_fetch_row($query)) {echo "<li><a href=\"javascript:ajaxpage('" . $row[1] . ".php', 'content');\">" . $row[1] . "</a></li>"; }?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/214359-echo-help-include-java-string/#findComment-1115504 Share on other sites More sharing options...
PFMaBiSmAd Posted September 25, 2010 Share Posted September 25, 2010 Sorry to be blunt, but every php/mysql book or basic php/mysql tutorial shows how to retrieve multiple rows from a query. You are asking something that is very basic, so it would seem that you have not bothered to learn the basic information that you need to know before you are attempting to do this with your data. (Before you can write a book, you must know how to write at all.) If you take the time to learn some of the basic php/mysql programming information, you can produce working code at least 10 times faster than if you just try things you might have seen without knowing what they mean or what each line of code actually does. A basic php/mysql tutorial that executes a query and iterates over all the rows that it returns - http://w3schools.com/php/php_mysql_select.asp Quote Link to comment https://forums.phpfreaks.com/topic/214359-echo-help-include-java-string/#findComment-1115515 Share on other sites More sharing options...
herghost Posted September 25, 2010 Author Share Posted September 25, 2010 Thans to both, I will do some further reading, I just like the learn as you go approach, once I can see something working I can then replicate it and learn as I go, I did have a read about, but I was looking at foreach and I could not find an example which took results from a database Quote Link to comment https://forums.phpfreaks.com/topic/214359-echo-help-include-java-string/#findComment-1115519 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.