I will need help again soon... I'm playing at the moment, but it could get messy... I'll let you know tomorrow
OK I need some help again This is what I have so far... $mysql_access = mysql_connect("localhost", "user", "pass"); mysql_select_db( "DBname", $link ) ; $sql = "SELECT `asin`, `name` FROM `freebs_items` ORDER BY `name` DESC"; $result = mysql_query($sql); $num = mysql_num_rows($result); $i=0; while ($i < $num) { $book_name = mysql_result($result,$i,"name"); $book_asin = mysql_result($result,$i,"asin"); echo ("<a href=\"$book_asin\">$book_name</a><br />"); $i++; } PHP: This is on the same page as the previous one - just adding something to the bottom... The problem is, I'm pulling the data from a different DB, so I guess I need to connect to it first (Hence the top couple of lines)... This isn't working though Can anyone see anything clearly wrong with this?
You don't need to connect again. As long as the database user that you login in with has permissions for both databases, you can specify a database and table name in a query, e.g. $sql = "SELECT `asin`, `name` FROM `DBname.freebs_items` ORDER BY `name` DESC"; PHP: . Also, dct is right, print out the MySQL error and the query if you detect a failure
I get this - I've also changed to what you suggested john... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/stretch/public_html/oweb/wp-content/plugins/phpinposts.php(40) : eval()'d code on line 4 That make any sense?
Stupid question (maybe) but your database is called DBName and you've changed the login details as it's a public forum to be ("localhost", "user", "pass");
Yep - this is what I have now... (DB name has been changed)... $sql = "SELECT `asin`, `name` FROM `DBName.freebs_items` ORDER BY `name` DESC"; $result = mysql_query($sql); $num = mysql_num_rows($result); $i=0; while ($i < $num) { $book_name = mysql_result($result,$i,"name"); $book_asin = mysql_result($result,$i,"asin"); echo ("<li><a href=\"$book_asin\">$book_name</a></li>"); $i++; echo mysql_error(); } PHP: That's the lot...
you mind doing a: print "number of records found = " . $num; after the: $num = mysql_affected_rows(); that way, we'll get to see how many records get returned... if it's 0, then the problem is with your query...
well, the return values for mysql_affected_rows are: "Returns the number of affected rows on success, and -1 if the last query failed." looks like you've got a syntax error with your query...
In the mySQL then? Hmmmmmm. So In the table 'freebs_items', I have two columns I would like to pull data from - 'asin' and 'name' I've been using $sql = "SELECT `asin`, `name` FROM `DBname.freebs_items` ORDER BY `name` DESC"; Can that *really* be wrong? I guess it must be, but it seems pretty straightforward...
i'd go back to your original syntax: $mysql_access = mysql_connect("localhost", "user", "pass") or die("Cannot connect to DB!"); mysql_select_db( "DBname") or die("Cannot select DB!"); $sql = "SELECT asin, name FROM freebs_items ORDER BY name DESC"; $result = mysql_query($sql);
Put the echo sql_error underneath every database statement you have in the file, especially including the connection ones. Edit: or like daboss says use die