sigmahokies Posted November 2, 2015 Share Posted November 2, 2015 (edited) Hi everyone I'm getting somewhere in PHP, but I am still have long way to go. I want to ask you...is there possible to have two execute the query from database? For example - $one = "select FirstName, Lastname, Local FROM Members WHERE Local = 'Yes'"; (Local member) $two = "select FirstName, Lastname, Local FROM Members WHERE Local = 'No'"; (Non-Local member) if ($one && $two) { (mysqli_num_rows($one) && mysqli_num_rows($two)) That is my script, but is it possible to have split in two col for "Yes" and "No". Please let me know if it is possible or not... if not, it means, I have to do completely seperate script between Yes and No (true/false). Thank you, Gary Edited November 2, 2015 by sigmahokies Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/ Share on other sites More sharing options...
gizmola Posted November 2, 2015 Share Posted November 2, 2015 We'd have to understand what you are trying to do. Are you simply trying to get the counts? SELECT Local, COUNT(*) as countof FROM MEMBERS GROUP BY Local You get 2 rows in the result, with the count of Local true vs false. Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525237 Share on other sites More sharing options...
Barand Posted November 2, 2015 Share Posted November 2, 2015 There is a multi query option but I have never found the need to use it. In you example I cannot see a need either. If you want to separate the local and non-local you can ORDER BY local. If, as it appears, you are only interested in how many of each SELECT local, COUNT(*) as total FROM members GROUP BY local; Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525239 Share on other sites More sharing options...
Barand Posted November 2, 2015 Share Posted November 2, 2015 SNAP! Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525240 Share on other sites More sharing options...
sigmahokies Posted November 3, 2015 Author Share Posted November 3, 2015 Hi Gizmola, I am trying to do is separate the yes and no from one columns that go to two columns. For example, I will like to have list of members are local, and list of member are non-local. I can put local and non-local on top of table, then list goes on under local, and list goes on under non-local that i created the one columns in database, i put some yes and no in one column under local on table in database. Get it? Please let me know if you need to understand what I said. Really, English is my second language. Thanks, Gary Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525316 Share on other sites More sharing options...
ginerjm Posted November 3, 2015 Share Posted November 3, 2015 Why not just query all the members but order them by local or non-local and then make your table heading row as your go through the results in a loop and look for when you change from local to non-local data? Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525319 Share on other sites More sharing options...
sigmahokies Posted November 3, 2015 Author Share Posted November 3, 2015 Order? It will go one columns, but i will like to have two columns on website that split from one column on the table. I created one column under "local" on the table, But I inserted a cell "yes" and "no" on one columns, so i will like to have split one to two columns on website that show separate the yes and no, one column show "yes" (true), the next columns show "no" (false). if you saying ORDER can split the yes and no as true and false into two columns? I will give it a try. P.S. I tried to insert two image to make clear example what I want to create, but seem this post doesn't have icon to insert an image... Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525321 Share on other sites More sharing options...
Solution Barand Posted November 3, 2015 Solution Share Posted November 3, 2015 try something like this <?php include('db_inc.php'); // defines HOST etc $db = new mysqli(HOST, USERNAME, PASSWORD, DATABASE); $sql = "SELECT firstname , lastname , local FROM member ORDER BY firstname, lastname"; $local = ''; $nonlocal = ''; $res = $db->query($sql); while (list($fn, $ln, $loc) = $res->fetch_row()) { if ($loc=='Y') { $local .= "$fn $ln<br>"; } else { $nonlocal .= "$fn $ln<br>"; } } ?> <html> <head> </head> <body> <table border='1'> <tr><th>Local</th><th>Non-Local</th></tr> <tr style='vertical-align: top;'> <td><?=$local?></td> <td><?=$nonlocal?></td> </tr> </table> </body> </html> 1 Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525323 Share on other sites More sharing options...
sigmahokies Posted November 4, 2015 Author Share Posted November 4, 2015 Hi Barand and Gizomla, I'm not sure I follow you, what i did do scipt in PHP in HTML: <!doctype html> <html> <head> <title>Local and Non-local Members</title> <link href="rcd.css" rel="stylesheet" type="text/css"> </head> <body> <table border="1" width="25%"> <tr><td><b><i>Local</i></b></td><td nowrap><b><i>Non-local</i></b></td></tr> <tr> <?php $local = "SELECT * FROM Members WHERE Local = 'Yes'"; $nonlocal = "SELECT * FROM Members WHERE Local = 'No'"; $local2 = mysqli_query($Garydb, $local); $nonlocal2 = mysqli_query($Garydb, $nonlocal); if (mysqli_num_rows($local2)) { while ($rows = mysqli_fetch_assoc($local2)) { echo "<tr><td nowrap>".$rows['FirstName']." ".$rows['LastName']."</td>"; if (mysqli_num_rows($nonlocal2)) { while ($row2 = mysqli_fetch_assoc($nonlocal2)) { echo "<td nowrap>".$row2['FirstName']." ".$row2['LastName']."</td></tr>"; } } } } ?> </tr> </table> </body> </html> This script just end up incorrect separate between local and nonlocal. I hope you can help... Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525479 Share on other sites More sharing options...
ginerjm Posted November 4, 2015 Share Posted November 4, 2015 I tried following you before, and just looked at this last post and still don't understand. How about giving us a real life example such as: Example 1: John Non1 John Non2 John Non3 ... ... ... jane local1 Jane local2 Jane local3 and show us how you want to see that output. What you gave us now gives you this: john non1 jane local1 jane local2 jane local3 john non2 john non3 My original interpretation of what you wanted was something like my Example 1: Non Locals: john non1 john non2 john non3 Locals: jane loc1 jane loc2 jane loc3 That is not what you want? Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525487 Share on other sites More sharing options...
Barand Posted November 4, 2015 Share Posted November 4, 2015 My guess, and what my code in #8 above gives, was Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525489 Share on other sites More sharing options...
sigmahokies Posted November 4, 2015 Author Share Posted November 4, 2015 Barand, EXACTLY what i am trying to make. Can you help? Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525503 Share on other sites More sharing options...
Barand Posted November 4, 2015 Share Posted November 4, 2015 I already gave you the code that produced that output. How much more help do you need? Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525504 Share on other sites More sharing options...
sigmahokies Posted November 4, 2015 Author Share Posted November 4, 2015 you are using OOP, I am using Procedural. That is why I don't get much from OOP. Is OOP and Proedural similar? your code in above of here doesn't work at all. Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525506 Share on other sites More sharing options...
ginerjm Posted November 4, 2015 Share Posted November 4, 2015 I wouldn't call Barand's code OOP. It's the same code I use and I don't use OOP very often at all. So - it doesn't work. Care to enlighten us as to what error you are getting or what makes you feel it is not working? Maybe post your code so we can see what you are running. Be sure you have php error checking turned on too!! Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525508 Share on other sites More sharing options...
Barand Posted November 4, 2015 Share Posted November 4, 2015 It worked well enough for me to produce that output. You may have to make one or two minor tweaks to adapt it to your database and table. Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525510 Share on other sites More sharing options...
sigmahokies Posted November 4, 2015 Author Share Posted November 4, 2015 (edited) Barand, your code is working now, but your code is not correctly, but i fixed it, finally, now it is working! Thank you, Barand! Edited November 4, 2015 by sigmahokies Quote Link to comment https://forums.phpfreaks.com/topic/299020-can-php-do-two-execute-queries-in-same-time/#findComment-1525523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.