PHP - Num_rows Problem
Hey guys I cant seem to find this error guess ive been looking at this screen to long to try and get this project done in time would appriciate if someone could take a fresh look at it and tell me where I went wrong. Basically im trying to get the number of entries returned by my query. I echoed out the query and manually entered it into phpmyadmin there is a 1 row result however whenever i kill $num_result it doesnt give me any output.
Code: [Select] <?php public function getNewMessages() { global $db,$db_table_prefix; $sql = "SELECT * FROM messages WHERE `to_id` = '".$db->sql_escape($this->user_id)."' AND `read` = 0"; $res = mysql_query($sql) or die (mysql_error()); $num_rows = mysql_num_rows($res); die ($num_rows); // does not return a value return $num_rows; } ?> Similar Tutorialsok really simple question. I'm going blind staring at this code so can someone please help. All I want to do is echo the number of rows in a table. Here is the code <?php $qCheckFirstLog = "SELECT * FROM logindetails WHERE email = '".$_SESSION['email']."'"; $rCheckFirstLog = mysql_query($qCheckFirstLog); $num_rows = mysql_num_rows($rCheckFirstLog); ?> Now there are 15 records with the session emails name in the table. I know the session email is there as it echos an email if I ask it too so thats not missing but when I put <?php echo $num_rows; ?> I get nothing!!!!!! Can someone please tell me what I'm doing wrong Thank you I have a table and the following code. Im not sure if im using rownum in the correct way as im not getting the result expected. $result = mysql_query("SELECT * FROM totem_ads"); $num_rows = mysql_num_rows($result); $random_row = rand(1, $num_rows); $ad_sql = mysql_query("SELECT * FROM totem_ads WHERE rownum='$random_row'"); while($row_advert = mysql_fetch_array($ad_sql)) { echo "<a href='" . $row_advert['link'] . "'><img src=$img_loc'" . $row_advert['image'] . "' alt='" . $alt_text['image'] . "'></a>"; } THe ad_sql displays as expected SELECT * FROM totem_ads WHERE rownum='1' however the while loop displays nothing which makes me wonder if im using rownum incorrectly. When i search for information on rownum I find all kinds of confusin statements from people posting in forums with problems and not the correct answer im looking for. I'm trying to write a plugin and when trying to see if a user ID is in an approved users table it does not want to cooperate. It doesn't error on any other $wpdb just this one. I'm not sure whats wrong, then again, I'm fairly new to OOP and WP Code: [Select] $wpdb->get_row("SELECT * FROM $wpdb->re_approvedusers WHERE user_id=$userid"); Full function code Code: [Select] function re_approved_user_verify($userid) { global $user_ID, $wpdb; //$userid = $this->re_secure($userid); $re_check = $wpdb->get_row("SELECT * FROM $wpdb->re_approvedusers WHERE user_id=$userid"); if($re_check == 0 || $re_check == NULL) { $success = 0; } else { $success = 1; } return $success; } Can anyone tell me what the problem is? $userid is obtained via the function if you're wondering. ERROR: Fatal error: Call to a member function get_row() on a non-object in /home/.../wp-content/plugins/re/functions.php on line 64 I'm creating a login that uses PDO statements, however when I try to count how many rows was selected, it gives me an error mentioning its an unidentified property, I always tried rowCount, but it did not work either... Notice: Undefined property: PDOStatement::$num_rows in /Users/JPFoster/Sites/Jaipai.Blog/engine.php on line 50 Here's my class method: Code: [Select] public function login($user, $pw){ $user = addslashes($this->user); $pw = md5($pw); $query = "SELECT * FROM `users` WHERE `username` = '".$user."' AND `password` = '".$pw."'"; //set up query $results = $this->pdo->query($query); if ($results->num_rows == 1){ $row = $results->fetch_assoc(); echo "Worked!"; //$this->set_session($row['id'], $row['username'], $row['email']); } else { echo "Your Username and Password did not match"; } //if user + passs match { redirect (member page) and set up sessions // Else ... Retry... } Any help with this will be greatly appreciated! Folks, Having trouble here. Forgot how you use the COUNT. Not interested in the num_rows due to it being slow compared to COUNT. I have users table like this: id|username|sponsor_username 0|barand|requinix 1|phpsane|alison 2|mickey_mouse|requinix Now, I want to check if a sponsor username exists or not. Such as does the entry "requinix" exists or not in one of the rows in the "sponsor_username" column. In our example it does twice and so the variable $sponsor_username_count should hold the value "2". Else hold "0". I get error: Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1
My code:
$stmt_1 = mysqli_prepare($conn,"SELECT COUNT(sponsor_username) from users = ?"); mysqli_stmt_bind_param($stmt_1,'s',$sponsor_username_count); mysqli_stmt_execute($stmt_1); //Show error if 'users' tbl was not successfully queried". if (!$stmt_1) { echo "ERROR 1: Sorry! Our system is currently experiencing a problem loading this page!"; exit(); } else { mysqli_stmt_bind_result($stmt_1,$sponsor_username_count); mysqli_stmt_fetch($stmt_1); mysqli_stmt_close($stmt_1); //Check if Sponsor Username in Url ($_GET) is already registered or not. If not then show "Invalid Url" or Link message. if ($sponsor_username_count < 1) { echo "<b>Invalid Url or Link!<br> Invalid Sponsor: \"$sponsor_username\"!</b><?php "; exit(); } }
Guys thanks for helping me solve the problem i had but now i have another problem and i am lost. i have included the code below for you to have overview.
This is the code:
<table style="width:100%; margin-left:auto; margin-right:auto"> Elo, I'm creating a very simple image list that is function generated which pulls the source from a table in my database, this is my code Code: [Select] $output = "<ul>"; $img_src = get_all_image_src($sel_event['id']); while($src = mysql_fetch_array($img_src)) { for($i=0;$i <= 9; $i++) { $output .= "<li>"; $output .= "<a"; $output .= " class ='album'"; $output .= " rel='group'"; $output .= " href='/images/gallery/'" . $src['img_src'] . $i; $output .= ".jpg"; $output .= " title='sample 1'"; $output .= ">"; //Image Thumb $output .= "<img"; $output .= " src='/images/gallery/'"; $output .= $src['img_thumb_src']. $i . ".jpg"; $output .= "alt='image01' "; $output .= "title='sample title' />"; $output .= "tae"; $output .= "</a>"; $output .= "</li>"; } } $output .= "</ul>"; return $output; and the img src doesnt seems to add up... my folder structure is Sandbox>image>gallery>2011>Mall>Event>Thumbs where Sandbox is the main directory. i tried echoing the $src['img_src'] and it displays correctly the data to be added (which is 2011/Mall/Event/ plus $i and a .jpg) .. sorry noob here... any thoughts? am i missing a simple detail? Hello everyone Just found this forum and really need some help. I'm trying to create a popup contact form for my product pages. I managed to get a php form from a random site and i cant get the form to pop up. http://www.e-sol.co.uk/printer-scanner-copier.php If someone could help i would be very grateful. The problem is whit the var $threadid . It dosent work here(it dosen't display the data from database): $dbh = "SELECT *FROM comments WHERE threadid = '".$threadid."' "; But if I assign a value before the that code the html page show correctly. Code: [Select] include("config.php"); $name = $_POST['name']; $comment = $_POST['comment']; $threadid = $_POST['threadid']; if($name & $comment) { $dbh="INSERT INTO comments (name,comment,threadid) VALUES ('$name','$comment','$threadid') "; mysql_query($dbh); } $dbh = "SELECT *FROM comments WHERE threadid = '".$threadid."' "; $req = mysql_query($dbh); while($row=mysql_fetch_array($req)) { echo "<li>"; echo "<br>"."<b>".$row['name']."</b></br>"."<br>".$row['comment']."</br>"; echo "</li>"; } Code: [Select] $('.submit').click(function(){ location.reload(); var name = $("#name").val(); var comment = $("#comment").val(); var threadid = $("#v").val(); var dat = 'name='+name+'&comment='+comment+'&threadid='+threadid; $.ajax({ type:"post", url:"comment.php", data:dat, success:function(){ console.log("dat"); } }); return false; }); so i want to call my php file with a query string to select a record out of a XML file... im close but cant get the variable i pass to be the record selected.. example... index.php?auction=1 i highlighted in red, where it doesnt pick up the proper row Code: [Select] <?php ini_set('display_errors', 1); error_reporting(E_ALL); $auction = $_GET{auction}; // parse the xml $xmlFileData = file_get_contents("items.xml"); $xmlData = new SimpleXMLElement($xmlFileData); [color=red]$location = $xmlData->item[$auction];[/color] //Retrieving the content from the selected item $title = $location->title; $value = $location->value; $itemnumber = $location->itemnumber; $description = $location->description; $donatedby = $location->donatedby; $image1 = $location->image1; $image2 = $location->image2; $image3 = $location->image3; $image4 = $location->image4; $image5 = $location->image5; $image6 = $location->image6; $image7 = $location->image7; $image8 = $location->image8; ?> <style> .itemimages img {width: 10px; height: 10px;} img.large {width: 100px; height: 100px;} </style> <script language="JavaScript" src="http://code.jquery.com/jquery-1.5.min.js" type="text/javascript"></script> <script> $().ready(function() { $(".itemimages img").click( $("#largepic").attr("src","this"); }); }); </script> <table border="1" cellpadding="10"> <tr> <td valign="top"> <img src="<?php echo $image1 ?>" alt="" border="0" class="large" id="largepic"><br> <div class="itemimages"> <?php // image 1 if (trim(''.$image1) != '') { echo "<img src='"; echo $image1; echo "' alt='' border='0'/> "; } // image 2 if (trim(''.$image2) != '') { echo "<img src='"; echo $image2; echo "' alt='' border='0'/> "; } // image 3 if (trim(''.$image3) != '') { echo "<img src='"; echo $image3; echo "' alt='' border='0'/> "; } // image 4 if (trim(''.$image4) != '') { echo "<img src='"; echo $image4; echo "' alt='' border='0'/> "; } // image 5 if (trim(''.$image5) != '') { echo "<img src='"; echo $image5; echo "' alt='' border='0'/> "; } // image 6 if (trim(''.$image6) != '') { echo "<img src='"; echo $image6; echo "' alt='' border='0'/> "; } // image 7 if (trim(''.$image7) != '') { echo "<img src='"; echo $image7; echo "' alt='' border='0'/> "; } // image 8 if (trim(''.$image8) != '') { echo "<img src='"; echo $image8; echo "' alt='' border='0'/> "; } ?> </div> </td> <td valign="top"> <?php echo $title ?><br> Estimated Value: <?php echo $value ?><br> Item Number: <?php echo $itemnumber ?><br><br> <?php echo $description ?><br><br> Donated by: <?php echo $donatedby ?><br> </td> </tr> </table> Hi, I am trying to write in an existing excel file. But for some reason, I can't open the workbook (but I know I have made similar code work before). Here I am just pasting the code upto the error line $filename="C:\\apache\\htdocs\\GAC2\\dload\\template.xls"; $excel = new COM("excel.application") or die("Unable to instanciate excel"); $excel->Visible = 1; $excel->DisplayAlerts = 1; try{ $wkb = $excel->Workbooks->Open($filename); }catch (Exception $e) { echo 'Caught exception: ', $e->getMessage(), "\n"; } //........ Later part of the code This returns the following error Code: [Select] Caught exception: Source: Microsoft Office Excel Description: Unable to get the Open property of the Workbooks class For record, the I have already validated the file location. And I have tried the following line instead without any positive result. Code: [Select] $filename="C:\apache\htdocs\GAC2\dload\template.xls"; Looking for any help please. -Abd You may see a lot of things wrong with the code below, but please bring it to my attention! I'm trying to advance my knowledge on OOP, but I'm trying my best to get the basics down. The below code, after selecting the two characters to fight, the page returns nothing, just blank. I'm pretty sure the error lyes within class_li.php, but I'm not exactly sure. Script is attached. Hows it going guys. I am currently having a problem. I had a program that worked. I migrated the website and now the program is broken. Any time i try to run it, i get this error: Quote Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/thegoo20/public_html/class/wordgame/wordgame.php on line 31 Here is the code at that point: Code: [Select] function changeword(){ $result = mysql_query("Select words from CurrentWords"); $totalwords = array(); while ($row = mysql_fetch_array($result)){ $totalwords[] = $row["words"]; } $_SESSION['word'] = $totalwords[rand(0, count($totalwords)-1)]; $_SESSION['scrambled'] = str_shuffle($_SESSION['word']); } where line 31 is the while statement. Any help would be appreciated. Thanks I am trying to use the following code snippet to return values from a database with a "," after each value apart form the last one. At the moment for testing I have 2 rows with values 1 and 3 $totalRows_Recordset3 equals 2 (I echoed this to check) $i=1; while($row_Recordset3 = mysql_fetch_assoc($Recordset3)) { if($i < $totalRows_Recordset3) { $str = $str.$row_Recordset3['reading'].","; $i=$i+1; } else { $str = $str.$row_Recordset3['reading']; $i=$i+1; } } I get the number 3 which is the last value in the database, but I can't see why I don't get "1,3" I am sure it is something simple but it just escapes me. Thanks in advance for any help Gordon Helloo ever one i need know In PHP the function giving the current time stamp value is time(). So we can write a line like below to get the current time stamp value. <? echo time(); ?> my Question is how to display any value on specific time( where value is stored in database )... Hi there, I have a map of America made in flash, where you click on a state and the page should display the SQL database information for that state in the HTML table - but instead all it shows is the first entry of the database regardless of which state you click and it doesn't display the 2 radio buttons. My code is as follows Flash Actionscript 3 (just showing one state) Code: [Select] function waClick(event:MouseEvent):void { var waURL:URLRequest = new URLRequest("restaurants.php?state=Washington"); navigateToURL(waURL, "_self"); } wa_btn.addEventListener(MouseEvent.CLICK, waClick); PHP code Code: [Select] <?php include("mvfconnect.php"); $theChoice = $_GET['state']; $query = "SELECT * FROM restaurants WHERE" .$theChoice; $result = @ mysql_query($query); if (!$result) { $message="Unfortunately we are having problems with this page, we promise to have it fixed as soon as possible"; die($message); } $num = mysql_num_fields($result); $i=0; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $show1=substr($row['state'],0,50)."..."; $show2=substr($row['city'],0,50)."..."; $show3=substr($row['rname'],0,50)."..."; $show4=substr($row['address'],0,50)."..."; $show5=substr($row['pnum'],0,50)."..."; $show6=substr($row['web'],0,50)."..."; $show7=substr($row['dishes'],0,50)."..."; $show8=substr($row['dish_details'],0,50)."..."; $show9=substr($row['challenges'],0,50)."..."; $show10=substr($row['challenge_details'],0,50)."..."; $show11=substr($row['youtube'],0,50)."..."; $show12=substr($row['images'],0,50)."..."; echo "<tr>". "<td>".$row['city']."</td>". "<td>".$row['rname']."</td>". "<td>".$row['address']."</td>". "<td>".$row['pnum']."</td>". "<td>".$row['web']."</td>". "<td>".$row['dishes']."</td>". "<td>".$row['challenges']."</td>". "<td id='state".$i."' style='display:none'>".$row['state']."</td>". "<td id='city".$i."' style='display:none'>".$row['city']."</td>". "<td id='rname".$i."' style='display:none'>".$row['rname']."</td>". "<td id='address".$i."' style='display:none'>".$row['address']."</td>". "<td id='pnum".$i."' style='display:none'>".$row['pnum']."</td>". "<td id='web".$i."' style='display:none'>".$row['web']."</td>". "<td id='dishes".$i."' style='display:none'>".$row['dishes']."</td>". "<td id='dish_details".$i."' style='display:none'>".$row['dish_details']."</td>". "<td id='challenges".$i."' style='display:none'>".$row['challenges']."</td>". "<td id='challenge_details".$i."' style='display:none'>".$row['challenge_details']."</td>". "<td id='youtube".$i."' style='display:none'>".$row['youtube']."</td>". "<td id='images".$i."' style='display:none'>".$row['images']."</td>". "<td><input type='radio' name='vid' id='vid".$i."' onclick='openVideo(".$i.")' /></td>". "<td><input type='radio' name='pic' id='pic".$i."' onclick='openImage(".$i.")' /></td>". "<td class='last'style='display:none'>".$show1." ".$show2." ".$show3." ".$show4." ".$show5." ".$show6." ".$show7." ".$show8." ".$show9." ".$show10."</td>". "</tr>"; $i++; } ?> I have used this code before and it has worked fine, can someone please help me out! Okay, so i'm using the basic php mysql insert into function but I have a strange (or maybe not so strange, I just don't get it..) problem.. I have two columns (do you call them columns? I don't really know for sure, whatever things that are in a table whatsoever). Name and Trailer. EDIT: they are TEXT's if that matters Name is really nothing important, just the name. But I want to embed trailers.. If I embed the Megavideo code below: Code: [Select] <object width="400" height="300"><param name="movie" value="http://www.megavideo.com/v/8UZFURZQ2b55ada04d73ae65c726a5383b9ee9d9"></param><param name="allowFullScreen" value="true"></param><embed src="http://www.megavideo.com/v/8UZFURZQ2b55ada04d73ae65c726a5383b9ee9d9" type="application/x-shockwave-flash" allowfullscreen="true" width="400" height="300"></embed></object> Everything works fine, no problems and no bullshit. But.. if I for an example try to embed this one (NovaMov): Code: [Select] <iframe style='overflow: hidden; border: 0; width: 400px; height: 300px' src='http://embed.novamov.com/embed.php?width=400&height=300&v=xngq7u8yejwbt' scrolling='no'></iframe> It doesn't work. It just doesn't insert. Is inserting an "iframe" a problem or something? I just don't get why the hell it would do this? Does anyone know anything about this? If so i'd be eager and very thankful to hear why and how to fix it. thanks in advance i have the following sql running on local but i get an error. the sql: $sql = "SELECT * FROM '".TBL_PARENTS."'" or die(mysql_error()); the config file: define('DB_PREFIX', 'forum_'); define('TBL_PARENTS', DB_PREFIX.'parents'); the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''forum_parents'' at line 1 the echoed sql: SELECT * FROM 'forum_parents' as you can see when it is echoed it looks fine. Any ideas? The server im using is wamp server. |