PHP - Mysql_fetch_row()
Alright, I have a question regarding mysql_fetch_row. The manual says: Quote
Returns an numerical array of strings that corresponds to the fetched row, or FALSE if there are no more rows . However, Code: (php) [Select] <?php $array = mysql_query(); $data = mysql_fetch_row($array); while ($data) { dosomething } Turns into an endless loop. I'm sure I'm missing something and I'm just looking for an explanation. Thanks. Similar TutorialsHello! I've been trying to work on a small project of mine but I keep encountering this: Quote Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\book-suggestion\test.php on line 21 In test.php, this is the only PHP code I seem to have and I haven't found anything wrong with it. For additional assurance, I copy-pasted the SQL statement directly from phpmyAdmin but it continues to give me an error so I know for a fact that the SQL query works and there is a result for such a query. Code: [Select] $db = mysql_connect("127.0.0.1",$db_user,$db_password, $db_name); if(!isset($db)) { echo 'Error connecting to database...'; } else { echo 'Success.'; } $query = mysql_query("SELECT * FROM `book-listing` WHERE 1"); $row = mysql_fetch_row($query); Any help with this? I've tried var_dump() and it returns boolean(false). Can't seem to figure out what the mistake is. I have a nagging question about loops when using mysql_fetch_row(). In other OOP languages whenever you use a for loop you have to use the variable you are incrementing to point to the right element in the array, but when you use mysql_fetch_row() you don't need to. Why is that? For example: in js/php/as you write: Code: [Select] for(i=0; i<length; ++i) { doSomething [i]row; } but when calling mysql_fetch_row you just write: Code: [Select] for(i=0; i<length; ++i) { doSomething row; } I'm just curious about how the loop finds its way to next row. Is it built in the mysql_fetch_row function already? Hi. I have a code and I'm trying to see if an e-mail address is stored in our database. Code: [Select] $query="SELECT email FROM users WHERE email='$email'"; $row=mysql_query($query); $result=mysql_fetch_row($row); if ($email==$result[0]) { return 1; } else { return 0; } I get this error: Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given. On this line: $result=mysql_fetch_row($row); Anyone knows why's broken? Can I do this in a better way ? Hi I am looking to be able to pass an array to mysql_fetch_row() not sure where i am going wrong. works fine like this. Code: [Select] mysql_select_db($DB_NAME); $new = mysql_query("SELECT * FROM {$DB_TABLE}"); if (!$new) { echo 'MySQL Error: ' . mysql_error(); exit; } $row = mysql_fetch_array($new); while ($row = mysql_fetch_array($new)) { echo $row['username'] . $DELIMITER . $row['firstname'] . $DELIMITER . $row['lastname'] . $DELIMITER . $row['password'] . $DELIMITER. "example@gmail.com" . $DELIMITER . "author"; echo "<br />"; } But really need too be able to do it this way. Code: [Select] mysql_select_db($DB_NAME); $new = mysql_query("SELECT * FROM {$DB_TABLE}"); if (!$new) { echo 'MySQL Error: ' . mysql_error(); exit; } $row = mysql_fetch_array($new); echo "<pre>"; //print_r($row); echo "</pre>"; $sam = array('username','firstname','lastname'); while ($row = mysql_fetch_row($new)) { echo $row[$sam] . $DELIMITER; echo "<br />"; } So it will just loop through the array so i can keep adding to it by just adding an extra parameter to the array. Any Help Stuck???? this Nofications appear.. Notice: Undefined index: id in C:\wamp\www\WAR\up3\view.php on line 4 Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\wamp\www\WAR\up3\view.php on line 9 invalid id this is my code. <?php require ('dbconnect.php'); // Connect to database $id = $_GET['id']; // ID of entry you wish to view. To use this enter "view.php?id=x" where x is the entry you wish to view. $query = "SELECT data, filetype FROM uploads where uploadid=$id"; //Find the file, pull the filecontents and the filetype $result = MYSQL_QUERY($query); // run the query if($row=mysql_fetch_row($result)) // pull the first row of the result into an array(there will only be one) { $data = $row[0]; // First bit is the data $type = $row[1]; // second is the filename Header( "Content-type: $type"); // Send the header of the approptiate file type, if it's' a image you want it to show as one print $data; // Send the data. } else // the id was invalid { echo "invalid id"; } ?> |