champbronc2 Posted June 16, 2011 Share Posted June 16, 2011 <?php $id = $_GET['d']; $servername="localhost"; $username="c_links"; $password="pass"; $conn= mysql_connect($servername,$username,$password)or die(mysql_error()); mysql_select_db("c_links",$conn); $query1 = mysql_query("SELECT url FROM links WHERE id='$id'"); $url = mysql_fetch_array($query1) or die(mysql_error()); $query2 = mysql_query("SELECT name FROM links WHERE id='$id'"); $name = mysql_fetch_array($query2) or die(mysql_error()); $query3 = mysql_query("SELECT size FROM links WHERE id='$id'"); $size = mysql_fetch_array($query3) or die(mysql_error()); ?> <html> blah blah blah <?php eco $id; ?> //THIS ONE ACTUALLY WORKS <?php echo $url; ?> <?php echo $name; ?> <?php echo $size; ?> </html> When I do this and I go to http://example.com/?d=xxxx, where ever I have $url $name and $size in my html, the output is "Array" when it should be actually outputting a URL or a name or size. The $id one is the only one that works in the HTML body. The page completely loads and there are no error messages displayed. What is wrong with the code? Shouldn't it query my database, then when I run fetch_array store whatever the result is into the variable??? Thanks for any help! Quote Link to comment https://forums.phpfreaks.com/topic/239589-trying-to-use-mysql_fetch_array-but-the-output-keeps-on-being-array/ Share on other sites More sharing options...
AbraCadaver Posted June 16, 2011 Share Posted June 16, 2011 You fetch 1 row which is an array of the data. Also, you will only get url because that is all you put in the query. $query1 = mysql_query("SELECT url, name, size FROM links WHERE id='$id'") or die(mysql_error()); $row = mysql_fetch_array($query1); $url = $row['url']; $name = $row['name']; $size = $row['size']; Quote Link to comment https://forums.phpfreaks.com/topic/239589-trying-to-use-mysql_fetch_array-but-the-output-keeps-on-being-array/#findComment-1230752 Share on other sites More sharing options...
fugix Posted June 16, 2011 Share Posted June 16, 2011 nooo you are echoing the contents of the array that mysql_fetch_array() outputs. by using the constructor echo() you are converting the array into a string which will always output "Array" do what abra said in order to correctly output your array values Quote Link to comment https://forums.phpfreaks.com/topic/239589-trying-to-use-mysql_fetch_array-but-the-output-keeps-on-being-array/#findComment-1230755 Share on other sites More sharing options...
champbronc2 Posted June 16, 2011 Author Share Posted June 16, 2011 Ohh, got it. Sorry, I am still learning but thanks for the help!! Works now. Quote Link to comment https://forums.phpfreaks.com/topic/239589-trying-to-use-mysql_fetch_array-but-the-output-keeps-on-being-array/#findComment-1230756 Share on other sites More sharing options...
AbraCadaver Posted June 16, 2011 Share Posted June 16, 2011 You fetch 1 row which is an array of the data. Also, you will only get url because that is all you put in the query. $query1 = mysql_query("SELECT url, name, size FROM links WHERE id='$id'") or die(mysql_error()); $row = mysql_fetch_array($query1); $url = $row['url']; $name = $row['name']; $size = $row['size']; Also, if you are only returning 1 row then you can put LIMIT 1 on the end of the query. Quote Link to comment https://forums.phpfreaks.com/topic/239589-trying-to-use-mysql_fetch_array-but-the-output-keeps-on-being-array/#findComment-1230757 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.