0

I have code in PHP:

<?php
// include 'connectss.php';
include 'koneksi.php';

$query= "CALL ws_booking('KLN','MDN','20131012','U15a',2,1,'A','jonie','ivhas,gavas','19900302,19901002','0815123456,08349857345','U77783,K77234','ronas','20100606','5EB9FE68-8915-11E0-BEA0-C9892766ECF2');";
//echo($query); 
$hasil = mysqli_query($koneksii,$query) or die(mysqli_error($koneksii));

while($row = mysqli_fetch_row($hasil))
{
    $trans_hold_id = $row[0];
}   

$kueri = " SELECT 0 as err_code,a.originations_label as org,
    a.destinations_label as des,
    date_format(a.depart_date,'%Y%m%d') as dep_date,
    b.vehicle_no as train_no,
    b.booking_no as book_code,
    get_pax_num_adult(a.booking_no) pax_num,
    get_pax_num_child(a.booking_no) pax_num_ch,
    sf_get_pax_nm(b.pax_id) pax_name,
    b.coach_code,
    b.coach_seq,
    b.seat_str_row,
    b.seat_str_col,
    (select sum(f.TOTAL) 
                    from   fares f, transactions tr 
                    where  tr.FARES_ID = f.FARES_ID 
                    and    tr.TRANS_HOLD_ID = a.TRANS_HOLD_ID) AS normal_sales,
    0 extra_fee,
    a.balance book_balance FROM   transactions_hold a, transactions b  WHERE      b.trans_hold_id = a.trans_hold_id
                    AND a.TRANS_HOLD_ID = '$trans_hold_id'
";
echo($kueri);
$hquery = mysql_query($kueri) or die(mysql_error());

$num_rows = mysql_num_rows($hquery);
echo($num_rows); ?>

The ws_booking is inserted into the MySQL database, and it returns $trans_hold_id to use in the second query. The $trans_hold_id has a value, but when I'm running the second query why does $num_rows return 0?

Note that the data are present in the database.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
  • 1
    Stored procedures might return buffered resultsets. Check for them by [`mysqli_store_result()`](http://php.net/mysqli-store-result). There might be not enough to use `mysqli_fetch_row()` from `CALL` query to obtain resultset. – BlitZ Sep 21 '13 at 17:32
  • 1
    @CORRUPT He's not using mysqli, he's using mysql. – Barmar Sep 21 '13 at 17:48
  • 1
    As @Barmar mentioned, your second query execution is using function from another extension. Note that `mysql_query` is not `mysqli_query`. They are different. – BlitZ Sep 21 '13 at 17:55
  • Ahh, I only looked at the bottom, not the top! – Barmar Sep 21 '13 at 17:56
  • but i have no problem with first query "CALL ws_booking('KLN',.... ", my problem is with the second query that return 0 in mysql_num_rows... – coder freaks Sep 21 '13 at 18:00
  • Since you never called `mysql_connect()` you can't use `mysql_XXX` functions. You can't switch between `mysqli` and `mysql` functions, you need to be consistent. – Barmar Sep 21 '13 at 18:02

1 Answers1

0

If it is returning 0, and data is present, then it means query is not correct, try running it directly through phpmyadmin or mysql console

I can see one problem with your query here

SELECT 0 as err_code,a.originations_label as org

You can use 0 as column name here, instead put this name inside i.e in following form0`

Manish Goyal
  • 700
  • 1
  • 7
  • 17