PHP - Just How Does Mysql_fetch_row() Work??
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? Similar TutorialsAlright, 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. 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 ? Hello! 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. 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"; } ?> Hi.., I use below method to export data to excel. header('Content-type: application/ms-excel'); header('Content-Disposition: attachment; filename=abc.xls'); if I run the script from the server. (http://localhost/export.php) it is work. (pop-up window if i want save or open the file) but if i run the script from the client (http://192.168.1.5/export.php) it is not work. (nothing happen) any idea how to solve this? This one requires lots of up front information: I have a page, for this example that I will call page.php. It takes get parameters, and for this example I'll call the parameter "step". So I have a URL like this: page.php?step=1 This page has a form with an action of page.php?step=1. The code on the page validates the posting information. If the information is bad, it returns the user to page.php?step=1; if it is good, it takes the user to page.php?step=2 via header( "location:page.php?step=2" ). So redirection is done by relative path, not full URLs. This all works as expected. Now what I've done is set .htaccess to be HTTPS for this page, via this code: # Turn SSL on for payments RewriteCond %{HTTPS} off RewriteCond %{SCRIPT_FILENAME} \/page\.php [NC] RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] This works (initially). However, once you try to post the form, it just redirects back to the step=1 version of the page. I really don't know how or why that would be. I'm not sure how else I can explain this or what other information you may have. But it's frustrating to not get a page working in HTTPS that works in HTTP. Very odd. Any suggestions? (I don't even really know the best location to figure out when/why it's redirecting back to the original page.) require_once 'includes/upload.class.php'; $upload = new uploads(); $details = $upload->getFileInformation($id); <?php echo $details['upload_desc']; ?> then here the class. require_once 'db.class.php'; class uploads extends database { private $uploadData; function uploadFile() { public function getFileInformation($id) { $this->uploadData = $this->readData("uploadfiles", "upload_id", $id); return $this->uploadData; } But it wont work! Some of you may have seen one of my many posts about email issues. Some users don't get them, and I have determined it is probably because we are marked as spam.
We are a service that grades sales team members on their phone skills. Listening to pre-recorded calls, grading and uploading them to our site, and then another part of our business looks them over and sometimes leaves a message that then get's forwarded to this persons work email.
I have determined there is ways to get marked as spam as default by not having an opt out link. This is not an option, these sales members employer has opted in, and the emails are going to work related accounts hosted at that employer. Also, if one of these staff members is not so bright, or disgruntled they may mark us as spam anyways. The bottom line is that we have very little control over whether we are or are not marked as spam.
So we want to start looking into sending text messages and this is where I start to question how good of an idea this is.
First off, if it was me, and the messages where being sent to a device that my employer did not provide, I would in no way want work related text messages coming to me. Unless there is a vested interest in getting them. IE, I'm the boss at this place and am always on the clock. What if you are on the bottom? It's just a job for you.
What if it is a pre-paid device, text messages cost money. What then? What if they don't even have, or want a cell phone?
The short of it is this. If I'm at a job that is just another job, and this employer tells me that I have to get these messages. I'm going to look for another job. I see the organizations having continuous issues and complaints from their employees. Thus us as a business having issues keeping clients.
What am I getting into here? What are your opinions on this matter? What are your recommendations as to alerting users of something on our site that we can rest assured are being received 100% of the time?
Thanks!
Nick
Hi there, As the question says i tried several things but i can't work it out and my knowledge about php isn't that well. i need help trying to get this delete feature to work its not deleting from the database (by the way i took out my database names and passwords at the top of the file) is it possible someone could help me, ive been working on this for like a week and cant figure out the problem. thanks! you can email me at spr_spng@yahoo.com picture 2.png is showing what it looks like Code: [Select] <?php $host="localhost"; // Host name $username="username"; // Mysql username $password="password"; // Mysql password $db_name="database_name"; // Database name $tbl_name="table_name"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <style> /*table affects look of the whole table look */ table { margin-left: auto; margin-right: auto; border: 1px solid #330000; border-collapse:collapse; width:70%; border-width: 5px 5px 5px 5px; border-spacing: 1px; border-style: outset outset outset outset; border-color: #330000 #330000 #330000 #330000; border-collapse: separate; background-color: #330000; #800517 f535aa #330000 school color #9A0000 school color2 #991B1E school color3 #CCCC99 school color4 #9A0000 } /*th is table header */ th { text-align: left; height: 2.5em; background-color: #330000; color: #FC0; font-size:1.5em; } /*td is table data or the cells below the header*/ td { text-align: left; height:1.0em; font-size:1.0em; vertical-align:bottom; padding:10px; border-width: 5px 5px 5px 5px; padding: 8px 8px 8px 8px; border-style: outset outset outset outset; border-color: #9A0000 #9A0000 #9A0000 #9A0000; background-color: #CCCC99; -moz-border-radius: 0px 0px 0px 0px; } </style> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action=""> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Pick Which Rows you want to delete, Then press delete.</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td> <td align="center" bgcolor="#FFFFFF">delete</td></tr> <?php while($rows=mysql_fetch_array($result)){ ?> <tr> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> </tr> <?php } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <? // Check if delete button active, start this // edited if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=delete_multiple.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> Code: [Select] <?php $path = "www.DOMAINHERE.com/images/showlogos/".$showNAME."_logo.jpg"; if (file_exists($path)){ echo "YES"; ?> <a href="index.php"><img src="/images/showlogos/<?=$showNAME?>_logo.jpg" width="190" height="62" /></a><br /><br /> <?php } else { echo "NO!"; echo $path; } ?> the result is echoing out NO! which means the file doesnt exist... however when i c+p the echo'd $path into my address bar, it shows the image.. Thanks Hi, me again; i'm curious why this don't work and what would in it's replace; echo "<b>".$row['name'].['id']."</b><BR>"; basically what I'm trying to do is that it read like this Your in game name is ['name'] with id set to ['id'] I figure if I can get the name and id beside each other I can figure out how to the add the your in game name is and with id set to part myself sorry guys don't mean to be a bother So I wanted to use a \ in order to stop PHP from registering my quotes. For some reason it does not seem to work. I am running PHP version 5.3.8. What am I doing wrong? Well, for those of you who use facebook, if you move pages from messages, to feed, to events or anything like that, you will notice the entire page doesn't load. At first, I though there must be some Ajax involved but then I realised that the page url is changing with new GET variables. So what is going on? What are they doing? Hi everybody *asian accent*, im trying to figure out how to display xml in php i know how to do things like <condition> <conditionId>4000</conditionId> <conditionDisplayName>Very Good</conditionDisplayName> </condition> for each blah blah as $item $condition = $item->condition->conditionId echo $condition; BUT........how do i get these values in XML to display in php this <searchResult count="2"> I want to get the value of count to display help please Here is my code: <?php class ScheduleRecord { private $month; private $day; private $year; private $hour; private $minute; private $type; private $employeeNumber; public function __construct($employeeNumber, $type, $month, $day, $year, $hour, $minute) { $this->employeeNumber = $employeeNumber; $this->type = $type; $this->month = $month; $this->day = $day; $this->year = $year; $this->hour = $hour; $this->minute = $minute; } public function getType() { return $this->type; } public function getEmployeeNumber() { return $this->employeeNumber; } public function getMonth() { return $this->month; } public function getDay() { return $this->day; } public function getYear() { return $this->year; } public function getHour() { return $this->hour; } public function getMinute() { return $this->minute; } public function getType() { return $this->type; } } $shcRec = new ScheduleRecord(3, "DayIn", 04, 04, 04, 04, 04); echo $shcRec ->getEmployeeNumber(); ?> error: The page cannot be displayed because an internal server error has occurred. the last line seems to be the problem. Hello, I am trying to make this work. what i am trying to do is to make a function that changes a variable back and forth. for example, I need to have a variable $bgcolorplace that is set to 1, as soon as the function is executed the variable $bgcolorplace changes to 0. The next time the function executes, variable should turn to 1 again. This pattern should repeat forever only when the function is executed. I am trying to use this to change the background color of a generated HTML code which will be on the webpage. Here is my script. <?php $input=($_GET['inputText']); //get info from JS $ItemNum='Item'.$input; //make a var with contents "Item" + the info from JS to display later $bgcolorplace; //var that keeps track of what color to make the next background $bgcolor; //keeps the color of the background for this execution function changebgcolor(){ if ($bgcolorplace=="0"){ $bgcolorplace="1"; //$bgcolor="444444" echo("0 to 1<br/>".$bgcolorplace."<br/>");//display which part of code is executed 1 to 0 or 0 to 1(can never get the script to run this part), this line is temp/test code }else{ $bgcolorplace="0"; //$bgcolor="ffffff" echo("1 to 0<br/>".$bgcolorplace."<br/>"); //display which part of code is executed 1 to 0 or 0 to 1(It works), this line is temp/test code } } //this next section I have temporarily commented for testing purposes, this section works fine /*$out="<tr bgcolor=#'".$bgcolor."' id='".$input."'><td align='center' width='5%'>".$input."</td><td align='center' width='30%'>bible</td><td align='center' width='50%'>Softcover</td><td align='center' width='5%'>45</td><td align='center' width='5%'>1</td><td align='center' width='5%'>45</td></tr>";*/ if ($input=='123'){ changebgcolor(); //echo($out); }else{ echo('none'); } ?> I get a responds of this everytime 1 to 0 1 this means that the function is being processed, but the value of $bgcolorplace is always a 1, it never changes to 0 like I am trying to inside the IF Else Statement. The commented Items are just my code that I have temp disabled while I try to figure out why my IF Else statement doesnt work. Help is much appreciated, and thank you in advanced. So, I have part of this snippet of code in my homepage and it pops up an inner window notification that briefly displays and then goes away...I'm looking to do it for a non-index.php page and it just isnt working. In the index.php page, it automatically occurs when the form loads and in this case, I need to invoke it...any help would be awesome..
It is the section where I'm echoing the JS script that isn't working.
<?php if($_GET){ if(isset($_GET['add'])){ /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "root", "test", "vendors"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } $name = mysqli_real_escape_string($link, $_REQUEST['vendor']); $company = mysqli_real_escape_string($link, $_REQUEST['company']); $type = mysqli_real_escape_string($link, $_REQUEST['type']); $email = mysqli_real_escape_string($link, $_REQUEST['email']); $soc = mysqli_real_escape_string($link, $_REQUEST['soc']); $status = mysqli_real_escape_string($link, $_REQUEST['status']); // Attempt insert query execution $sql = "INSERT INTO vendor_data (name, company, type, email, soc, status) VALUES ('$name', '$company', '$type', '$email', '$soc', '$status')"; if(mysqli_query($link, $sql)){ echo ' <script type="text/javascript"> $(document).ready(function(){ demo.initChartist(); $.notify({ icon: "pe-7s-gift", message: "TESTING!" },{ type: "info", timer: 4000 }); }); </script>'; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); } } ?> <!doctype html>
|