0

I am trying to return the result from this SQL function

<?php

require_once "func.php";
require_once "websockets.php";

//  private $curResultId;
//  private $MaxResult;
//  private $MinResult;

for( $i = 0; $i<50; $i++ ) {


    $row = db_fetch_item("SELECT resultid FROM ResultPackage 
        where ResultPackage.slotid like '%1'
        and ResultPackage.PackageID like '%1%'
        ORDER BY resultid desc LIMIT 1");

var_dump($row);
}

?>

However when i run it it returns the following:

array(1) { ["resultid"]=> string(2) "14" }

How do I correct it so its just 14

Rnadmo
  • 41
  • 4
  • 2
    `int + string + int` are you sure what you're doing? – u_mulder Jan 27 '17 at 18:51
  • 1
    in php use dot for concat not + (is not javascript) mt_rand($this->MinResult,$this->MaxResult) . ", SLOTID=". $slot_id – ScaisEdge Jan 27 '17 at 18:52
  • @u_mulder, Funnily enough I'm not sure what Im doing hence why I am posting on a help forum.... – Rnadmo Jan 27 '17 at 18:59
  • @Fred, thanks for the link. Even when I change the bottom line to var_dump($this->MinResult); Still no results are returned – Rnadmo Jan 27 '17 at 19:01
  • you will need to update your question with the new code you're now using. – Funk Forty Niner Jan 27 '17 at 19:02
  • There are some irregular quotes in your query so I hope those aren't present in your original source. `‘%1'` should be `'%1'`: Note the leading quote on the first. – tadman Jan 27 '17 at 19:13
  • @tadman, thanks, I have corrected this but still it doesnt work. – Rnadmo Jan 27 '17 at 19:17
  • 2
    Saying "doesn't work" is a form of giving up and it's really annoying to hear. You need to work to find some reason why it's not working. Error messages are best. You need to try simplifying the query until it does work, then incrementally add things back until it doesn't to identify what changes break it. – tadman Jan 27 '17 at 19:20
  • The loop `for( $i = 0; $i<500000; $i++ )` with a `var_dump()` at the end will almost keep spamming the console / browser long after all the possible results have been obtained. The number of times a loop may be executed should depend on the size of the result set you're dealing with. – Dhruv Saxena Jan 27 '17 at 19:41
  • @tadman, understood. At the moment there doesnt appear to be an error it is just not returning any results. – Rnadmo Jan 27 '17 at 19:50
  • What is `db_fetch_item`? It's not a standard PHP function. –  Jan 27 '17 at 21:06

0 Answers0