Selecting mutiple records problem.....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Ok Thanks for the script,

This is what i'm getting
HotelRoomID: array(2) {
[0]=>
string(2) "24"
[1]=>
string(2) "38"
}
and only "38" is outputting....Hmmmm
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

But now you didn't get the warning for line 21?
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

volka wrote:But now you didn't get the warning for line 21?
No....
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you change anything else?
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

volka wrote:Did you change anything else?
No, i only get those errors when i edit the URL, apart from that i dont get the errors

This is what the URL prints for the hotel room ID when i dont edit it:
http://pb-sql/roomhold.php?datefrom=19% ... D%5B%5D=24[/b]&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&HotelRoomID%5B%5D=38
When i do edit the url I for the first array(string(2) "24") i dont get any errors:
http://pb-sql/roomhold.php?datefrom=19% ... lRoomID=24[/b]&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25%2F06%2F2007&datefrom=19%2F06%2F2007&dateto=25
When i edit it for the second array output(string(2) "38", i get this error output,

HotelRoomID: string(2) "38"

Warning: Invalid argument supplied for foreach() in C:\Inetpub\wwwroot\salessys\roomhold.php on line 22


Notice: Undefined variable: count in C: line 42
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ghadacr wrote:No, i only get those errors when i edit the URL, apart from that i dont get the errors
You've edited the url in a way that no array is created.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

When the Variables are passed into the script without editing the URL this is what i get:
HotelRoomID: array(2) {
[0]=>
string(2) "46"
[1]=>
string(2) "47"
}
and i have just noticed the arrays are not giving indvidual numbers its all "2"'s Hmm what do you think...
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

ghadacr wrote:and i have just noticed the arrays are not giving indvidual numbers its all "2"'
:?:
Do you mean the 2 in
ghadacr wrote:string(2)
?
That only indicates that the string has a length of 2 bytes.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

Sorry i now i understand it was my Java programming making me look at the array differently...
What do you think could be the problem...because only one record is being ouputed and that seems to be the greater HotelRoomID record number..
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

because you first process all elements of $_GET['HotelRoomID'] and then loop through the last mssql result

try

Code: Select all

$reso=mssql_query($query);

$count=mssql_num_rows($result);
echo '<div>Debug: $count=', $count, "</div>\n";

}}
?>


<form method=get name=f1 action='confirmmholdroom.php'>
     <?php
$i=0;
echo "<div>Debug: while ($i < $count) { </div>\n";
while ($i < $count) {

$rows=mssql_fetch_array($result);
and take a look at the output.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

This is the output result:
Debug: $count=1
Debug: $count=1
Debug: while (0 < 1) {
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Yes, and that tells you.... ?
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

There is only one record being ouputted.....
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

hm, maybe the output was to subtle. Next try

Code: Select all

$dateto = $_GET['dateto'];

if(isset($_GET['HotelRoomID']))
{
  foreach($_GET['HotelRoomID'] as $k=>$k1)
  {
    echo "<fieldset><legend> foreach($k => $k1) </legend>\n";
    $sql="SELECT * FROM HotelRooms WHERE HotelRoomID=$k1";
    $ques="SELECT dbo.Hotels.HotelName FROM Hotels INNER JOIN HotelRooms ON dbo.Hotels.HotelID = dbo.HotelRooms.HotelID WHERE HotelRoomID=$k1";
    $query="SELECT dbo.RoomAssociations.RoomAssociation FROM RoomAssociations INNER JOIN HotelRooms ON dbo.RoomAssociations.RoomAssociationID = dbo.HotelRooms.RoomAssociationID WHERE HotelRoomID=$k1";
    
    echo "mssql_query($sql) <br />\n
          mssql_query($ques) <br />\n
          mssql_query($query) <br />\n";
    
    $result=mssql_query($sql);
    $res=mssql_query($ques);
    $reso=mssql_query($query);

    $count=mssql_num_rows($result);
    echo 'count=', $count;
    echo '</fieldset>';
  }
}
?>
<form method=get name=f1 action='confirmmholdroom.php'>
<?php
$i=0;
while ($i < $count) {
  echo "while ($i < $count)\n";
  $rows=mssql_fetch_array($result);
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post by ghadacr »

What i'm starting to see is that $count=mssql_num_rows($result); is identifying each record with a "1" instead of incrementing each record so 1, 2, 3 ect....

foreach(0 => 46) mssql_query(SELECT * FROM HotelRooms WHERE HotelRoomID=46)
mssql_query(SELECT dbo.Hotels.HotelName FROM Hotels INNER JOIN HotelRooms ON dbo.Hotels.HotelID = dbo.HotelRooms.HotelID WHERE HotelRoomID=46)
mssql_query(SELECT dbo.RoomAssociations.RoomAssociation FROM RoomAssociations INNER JOIN HotelRooms ON dbo.RoomAssociations.RoomAssociationID = dbo.HotelRooms.RoomAssociationID WHERE HotelRoomID=46)
count=1

foreach(1 => 47) mssql_query(SELECT * FROM HotelRooms WHERE HotelRoomID=47)
mssql_query(SELECT dbo.Hotels.HotelName FROM Hotels INNER JOIN HotelRooms ON dbo.Hotels.HotelID = dbo.HotelRooms.HotelID WHERE HotelRoomID=47)
mssql_query(SELECT dbo.RoomAssociations.RoomAssociation FROM RoomAssociations INNER JOIN HotelRooms ON dbo.RoomAssociations.RoomAssociationID = dbo.HotelRooms.RoomAssociationID WHERE HotelRoomID=47)
count=1

while (0 < 1)

Post Reply