PHP - Moved: Large Json For Loops - Show Results Code?
This topic has been moved to JavaScript Help.
http://www.phpfreaks.com/forums/index.php?topic=355144.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=329323.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=333337.0 Hello, Here's the weird thing, some of the pages shows the results, and some pages just won't show results at all, and I'm not getting any errors here is the one that doesn't Code: [Select] <? function display_mptt($user) { global $db; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id='25'"; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Users List</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE 'left' BETWEEN '".$row2['left']."' AND '".$row2['right']."' ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)or die(mysql_error())) { // only check stack if there is one $count = mysql_num_rows($result); if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title // add this node to the stack $var3 = '10'; echo "<table width='589' border='1'> <tr> <th>ID</th> <th>Name</th> </tr>"; echo "<tr><td><a href=\"user.php?id=".$row['id']."\">".$row['id']."</a></td>"; echo "<td>" . $row['title'] ." </td>"; echo "</tr>"; echo "</table>"; $right[] = $row['right']; } } display_mptt(1); ?> and here is the page that does Code: [Select] <? function display_mptt($user) { global $db; $id = $_GET['id']; // retrieve the left and right value of the $root node $sql2 = "SELECT * from mptt where id= ".$id.""; $result2 = mysql_query($sql2 ,$db); if(!$row2 = mysql_fetch_array($result2)) echo mysql_error(); echo '<h1>Your Tree</h1>'; // start with an empty $right stack $right = array(); // now, retrieve all descendants of the $root node $sql = "SELECT * from mptt WHERE `left` BETWEEN ".$row2['left']." AND ".$row2['right']." ORDER BY 'left' ASC"; $result = mysql_query($sql ,$db); // display each row while ($row = mysql_fetch_array($result)) { // only check stack if there is one if (count($right)>0) { // check if we should remove a node from the stack while ($right[count($right)-1]<$row['right']) { array_pop($right); } } // display indented node title echo str_repeat(' ',count($right)).$row['title']."<br>"; // add this node to the stack $right[] = $row['right']; } } display_mptt(1); ?> I am using Guzzle as a HTTP client, and the following script results in the following error: $response = $this->httpClient->request('GET', "http://$this->host:$this->port/query", ['query' => $data]); $body = $response->getBody(); $rs=json_decode($body, true); Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 136956008 bytes) in /var/www/vendor/guzzlehttp/psr7/src/Stream.php on line 80 What are the work arounds? Instead of trying to convert it into an array all at once, how can I do so in pieces? I know the expected format so it seems I will need to read just the appropriate amount of bytes and then decode parts at a time. Seems like a pain. Are there any classes designed to do so, or can any of the following Guzzle built in methods be used? Thanks Guzzle Response methods: __construct getStatusCode getReasonPhrase withStatus getProtocolVersion withProtocolVersion getHeaders hasHeader getHeader getHeaderLine withHeader withAddedHeader withoutHeader getBody withBodyGuzzle Body methods: __construct __destruct __toString getContents close detach getSize isReadable isWritable isSeekable eof tell rewind seek read write getMetadataThis topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=330251.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=314194.0 here is some simple code for getting and displaying fata from a database Code: [Select] $sql="SELECT * FROM messages WHERE m_id = '".$id."'"; $result = mysql_query($sql); <table border='0' cellspacing="4"> while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<th>Message</th>"; echo "</tr>"; echo "<tr>"; echo "<td>" . $row['message'] . "</td>"; echo "</tr>"; } now ive used that while loop to display those results how can i do that again without having a new SQL statement. i cant do 2 while loops because the first one has already got to the end of the amount of rows basically how can i have another while loop displaying those same results again? Hello, Having a bit of a tough time understanding what is going on in my brain! I'm basically pulling some data from an API using CuRL, which is working fine. The structure of the data is: [data][tickets] - tickets being an array of support tickets in the system, which then contains ticketNumber, title, content. I want to display these values in a list, I have this code currently: if ($err) { echo "cURL Error #:" . $err; } else { $return = json_decode($response, true); foreach($return as $key) { echo $key["tickets"][1]['ticketNumber']." - "; echo $key["tickets"][1]['title']." - "; echo $key["tickets"][1]['content']; } } Which obviously returns the ticketNumber, title & content of the first support ticket in the array, but I want to loop through and display that information for each ticket! Can anyone advise as to where I am going wrong? I think I need to utilise the ["tickets"][x] but not sure how!
Thanks in advance! Steve Hello - I am connecting to MySql and running a query. If I use a foreach loop, I can iterate over the results and have them print to screen. However, when I try the below everything is null!
How can I add the results of my MySql query to a php array?
<?php $con=mysqli_connect("site", "user", "psasswr=ord", "db"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql="SELECT * FROM test LIMIT 10"; $result = mysqli_query($con,$sql); echo json_encode($result); mysqli_free_result($result); mysqli_close($con); ?>
but what this prints is: {"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null} This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=307147.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=321687.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=323958.0 Hi all, Just to check if it is possible to have 2 while loops in a single code? Below are my codes. SQL code $tutor_id = mysqli_real_escape_string($dbc, $_GET['tutor_id']); $query = "SELECT tl.level_id, tl.level_name, ts.subject_id, ts.subject_name, tsl.subject_level_id, IF(tosl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl INNER JOIN tutor_subject_level AS tsl USING (level_id) INNER JOIN tutor_subject AS ts USING (subject_id) LEFT JOIN tutor_overall_level_subject AS tosl ON tosl.subject_level_id = tsl.subject_level_id AND tosl.tutor_id = '{$tutor_id}' ORDER BY tl.level_id, ts.subject_name"; $sql = mysqli_query($dbc, $query) or die(mysqli_error($dbc)); $query1 = "SELECT tl.level_id, tl.level_name, IF(tslvl.tutor_id='{$tutor_id}', 1, 0) as checked FROM tutor_level AS tl LEFT JOIN tutor_selected_level AS tslvl ON tslvl.level_id = tl.level_id AND tslvl.tutor_id='{$tutor_id}' ORDER BY tl.level_id, tl.level_name"; $sql1 = mysqli_query($dbc, $query1) or die(mysqli_error($dbc)); PHP code (2 while loops) //Process the results $checkboxes = ''; //Create variable for output $current_level_id = false; //Flag to check when records change level while($data = mysqli_fetch_array($sql)) //Iterate throug the DB results { if($current_level_id != $data1['level_id']) //Determine if this level is different from the last { print_r ($data); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } //$checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); while($data1 = mysqli_fetch_array($sql1)) { print_r ($data1); $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } //Call the createLevelCheckboxes() function to generate the HTML for the LAST level records $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); When I try to upload a file larger than the server's max limit, the following code is not executed. How am I supposed to inform the user that their file is too large? NOTE: I've stripped the code down for this post. Code: [Select] <?php if(isset($_POST['submit'])) { echo "test.."; } ?> <html> <head> <title>Upload Test</title> </head> <body> <form action='' enctype='multipart/form-data' method='POST'> <input type='file' name='file_upload' /> <input type='submit' name='submit' value='upload' /> </form> </body> </html> Hello dear friends Let say i've a huge database of 100,000 entries Code: [Select] my_table (id,name) and i'd like to call all the entires to be shown by this code Code: [Select] $conn = mysql_connect('localhost','USER','PASS') or die(mysql_error()); mysql_select_db('my_table',$conn); $sql = "SELECT * from my_table"; $result = mysql_query($sql,$conn); while ($row = mysql_fetch_array($result)){ $name = $row['name']; $id = $row['id']; echo $name; echo "<br>(done)<br>"; } The problem The problem that makes me almost gonna cry,it takes long time to load then it will showing names (remember my_table of 100,000 entries) all at once and sometimes it sudden shows huage amount once or even sometime it hang up. My question Is there any way that i can call it so that it showing me results one name by one name like streaming name1 (done),name2 (done),name3 (done),name4 (done),name5 (done),......etc not showing all at once i'm afraid it may needs some ajax idea or somehow i really don't know but this is important to me so your help is very useful to me. so anyone please helps me cause it would really save my hosting ram otherwise they would suspend me Hi, I'm trying to fetch rows of data from a mysqli table and display them in the browser in categories. I have the while loop working fine, but I want to break the results down into categories, instead of one big list sorted by a field using ORDER BY. So for example, let's say I have a database table containing people's names, email address, phone numbers, etc. and I want to display them in the browser in separate tables by the city in which they live (each city name would be a h1 or h2 tag) and the appropriate rows would be displayed under each heading, sorted by the person's name. I can do it by using multiple while loops, separating each city into it's own array and then repeating my html table code a bunch of times, but I know there has to be a much cleaner way. Can anyone point me in the right direction? Thanks! Hello all, I am making a database with all the Boeing deliveries sorted by month. I made a index with all the months and when you click on a month you will get a full list of the type and quantity of aircraft that has been deliverd. I have two problems and I can't figure it out. The first problem I have, is that I want to show the visitors which airline has bougt which type of aircraft and how many. The second problem I have is a want to show them the total amount of deliveries, not just per type of aircraft, but a total number. Here are some shots of my problem and what I have: This is how my MYSQL-database lookes like. The columns I have a id, day, month, year, airline, aircraft, amount (just a simple translation of the Dutch words ). As you can see, there are some airlines that received one type of aircraft two times (TUI Travel PLC has received 2x Boeing 737-800). Keep this in mind, I will get back to this. This is the table on my website. The first column shows the type of aircraft. The secon column shows us how many of that type has been deliverd. In the last column I want to have all the airlines that has received that type of aircraft. As I mentioned above, TUI Travel PLC has received 2x B737-800, so in the row of B737-800 I want to have TUI Travel PLC (2x). If the airline received more then 1 aircraft, I would like to have (.....x) (and the amount on the dots --> TUI example: 2 aircraft, so 2x). So you will get TUI Travel PLC (2x). This is the code I have so far (sorry I am a real noobie in PHP/MYSQL so my programming ain't that great ) Code: [Select] <?php mysql_connect(".....", ".....", ".....") or die(mysql_error()); mysql_select_db(".....") or die(mysql_error()); $maand = $_GET['maand']; $jaar = $_GET['jaar']; $query = "SELECT aircraft, jaar, maatschappij, COUNT(maatschappij) FROM deliveries_orders_boeing WHERE maand = '$maand' AND jaar = '$jaar' GROUP BY aircraft"; $result = mysql_query($query) or die(mysql_error()); // Print out result echo "<br /><h3>Boeing deliveries ".$maand." ".$jaar."</h3><br /> <table border='0' width='700'>"; while($row = mysql_fetch_array($result)){ echo "<tr><td id='aircraft'>". $row['aircraft']. "</td><td id='aantal'>". $row['COUNT(maatschappij)'] ."</td><td id='maatschappijen'>different companies</td></tr>"; } echo "<tr><td id='totaal'>Totaal</td><td id='totaal_aantal'>....</td><td></td></tr></table>"; ?> </td> </tr> </table> Maybe a little confusing, but I hope someone can help me with this. Kind regards, Flyboeing This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=315198.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=322125.0 hi guys i am building a voting system for my gaming website people sign up for matches, and those will be played at 3-5 different maps people can vote for wich maps they want to play each player can choose 3 maps, also 3 x the same map now the results of that voting system are shown on the page like this There is 1 vote for Map 1 There are 5 votes for Map 2 There is 1 vote for Map 3 There are 2 votes for Map 7 There is 1 vote for Map 4 There is 1 vote for Map 5 There are 8 votes for Map 8 now i want to make a script that picks the maps that will be played, so only show the 3-5 best results in the example above it woud be 2 x map 8 and 1x map 2 but im not sure how to start on this the db table of the votes is built like this id matchid playerid mapid mapname 1 113 195 1 NukeTown 2 113 195 2 Grid 3 113 195 1 NukeTown 4 114 195 1 NukeTown 5 114 195 1 NukeTown any advice or thoughts on this? thanks |