php - How to output multiple rows from an SQL query using the mysqli object -


Assuming that the mysqli object is already instantiatied (and connected) with global variable $ mysql, here is the code I am trying to work together to work with

  Listing of class {private $ mysql; Function getListingInfo ($ l_id = "", $ category = "", $ subcategory = "", $ username = "", $ status = "active") {$ condition = "` condition` = '$ status' "; If ($! Below ($ l_id)) $ bet = "And` L_ID` = '$ l_id' "; If ($ ($ category) empty down! = "And` category` = '$ range'"; If (below! ($ Subcategory)) $ bet = "And` subcategory` = '$ subcategory'"; If (empty! ($ Username)) $ bet = "AND`Username '=' $ username ''; $ result = $ IT- & gt; MYSCL- & gt; query (" Select where $ a bet is from ") Choose or die ('Error fetching the value '); $ This-> listing = $ result-> fetch_array () or die (' object could not be created '); Forex = $-> $ Value): $ info [$ key] = stripslashes (html_entity_decode ($ value)); endforeach; return $ info;}} There are several hundred entries in the DB and when I $ Results-> fetch_array () I call it a The first line is given in the Db in the queen. However, when I try to call the object, I may not have to use more than the first row, for example: $ listing_row = new listing; while ($ listing = $ Listing_row-> getListingInfo ()) {echo $ list [0];}  

This produces an endless loop of the same line in the DB. Why does not it move in the next line? Transfer the code:

  $ this-> listing = $ Result-> fetch_array () or die ('could not create object'); Forex Currency ($ this-> List = & gt; $ value as the $ Key): $ info [$ key] = stripslashes (html_entity_decode ($ value)); Endforeach;  

If I take it outside the orbit, then it works in exactly the same way as expected at a time when the looping becomes through the content. Is there a way to write it so that I can call fetch_array () in class and still keep the loop through the record?

Your object is fundamentally flawed - even when you call the getListingInfo () method, even then Every time the query resumes. Also, mysql_fetch_array () does not bring the entire result set, it only receives the next line, so your method boils with them:

  1. Query
  2. First line returned
  3. returned the first row

Each call for the object is a new query, one New makes results set, and therefore will never be able to get rows 2, 3, etc ....

Unless your data set is "huge" (i.e.: you want to set as big / php memory_limit), do not get the whole set and process it at all at one time There is no reason for it, as shown in the reply of Yakub above.

As a side note, I use StreeSlash to surprise me that your PHP installation is magic_quotes_gpc enabled. This functionality has been degraded for a long time and has been removed from PHP even when v6.0 is out. Will go If your code runs on this kind of installation then it can erase the legitimate escape from the data. Also, it is generally a bad idea to store Encoded / Escape data in the database. DB should have a "virgin" copy of the data, and then you can process it as necessary (escape, quote, etc ...) as per the requirement of the processed version.


Comments

Post a Comment

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -