Hack Forums
[PHP] PHP API issue only using one API rather than all that is stored in DB - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Web Development (https://hackforums.net/forumdisplay.php?fid=183)
+---- Thread: [PHP] PHP API issue only using one API rather than all that is stored in DB (/showthread.php?tid=5701852)



PHP API issue only using one API rather than all that is stored in DB - Fiend - Aug 23, 2017

PHP API issue only using one API rather than all that is stored in DB

i spent hours working on this to release to public but this one issue has me confused it will only send to 1 API

PHP Code

<?php 
                                                $insertLogSQL 
= $odb -> prepare("INSERT INTO `logs` VALUES (NULL, :user, :ip, :port, :time, :method, UNIX_TIMESTAMP(), '0')");
                                        
$insertLogSQL -> execute(array(':user' => $_SESSION['username'], ':ip' => $host, ':port' => $port, ':time' => $time, ':method' => $method));
                                        
$SQLSelectAPI = $odb -> query("SELECT `api` FROM `api` ORDER BY RAND () LIMIT 1");
                                        
$SQLSelectAPI2 = $odb -> query("SELECT `api` FROM `api` ORDER BY RAND () LIMIT 2");
                                        while (
$show = $SQLSelectAPI -> fetch(PDO::FETCH_ASSOC))
                                        {
                                            
$arrayFind = array('[host]', '[port]', '[time]', '[method]');
                                            
$arrayReplace = array($host, $port, $time, $method);
                                            
$APILink = $show['api'];
                                            
$APILink = str_replace($arrayFind, $arrayReplace, $APILink);
                                            
$ch = curl_init();
                                            
curl_setopt($ch, CURLOPT_URL, $APILink);
                                            
curl_setopt($ch, CURLOPT_HEADER, 0);
                                            
curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
                                            
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                                            
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
                                            
curl_exec($ch);
                                            
curl_close($ch);
                                        } 



* - Payload - Aug 23, 2017

It looks like you aren't calling $SQLSelectAPI2


* - Fiend - Aug 23, 2017

(Aug 23, 2017 04:45 PM)Payload Wrote:  It looks like you aren't calling $SQLSelectAPI2

Can you help me i'm clueless at mysql i struggle alot at it.


* - Payload - Aug 23, 2017

(Aug 23, 2017 04:55 PM)Alerts Wrote:  Can you help me i'm clueless at mysql i struggle alot at it.

I don't want to steer you in the wrong direction as i'm still learning too, but from what I can tell the while loop is only being performed on $SQLSelectAPI , not $SQLSelectAPI2.

In other words you are only showing the results of the first query, not the second.