Hi!
i'm a sudent and currently developing the SMS based application for directories search. Looping problems occured with my php code. I've tried many ways but it didn't worked. The result for the address that have been queried only appear once.Why does it happen and how to resolve it? Below is the sample code and its result..
$typenum = sizeof($requestypeid);
echo $typenum;
if ($typenum == 1){
echo "{GSMSMS}{}{}{$sender}{HARAP MAAF, TIADA REKOD DITEMUI}";
}
else{
for($i=0; $i<$typenum; $i++){
$typesubid = "select * from subdirectory where
typeid='$requestypeid[$i]'";
$typeidsub = mysql_query($typesubid);
$types[] ="";
$subtype[]="";
$phone[] ="";
$website[]="";
$address[]="";
$description[] = "";
while ($row = mysql_fetch_array($typeidsub))
{
$types[]= $row["typeid"];
$subtype[]= $row["subtypeid"];
$phone[]= $row["phoneid"];
$website[]= $row["webid"];
$address[]= $row["addressid"];
$description[]=$row["descriptionid"];
}
}
$result = "";
$subdirtypenum = sizeof($types);
for($j=0; $j<$subdirtypenum; $j++){
//to find correct typename according to smsrequest
$typename = "";
$typen = "SELECT * FROM type where typeid='$types[$j]'";
$tname = mysql_query($typen);
while ($typen = mysql_fetch_array($tname))
{$typename = $typen["typename"];}
//to find correct subtypename according to smsrequest
$subtypename = "";
If (!empty($typename)){
$subtype2 = "SELECT * FROM subtype where subtype like '%$b%'
AND subtypeid = '$subtype[$j]'" ;
$sname = mysql_query($subtype2);
while ($subname = mysql_fetch_array($sname))
{$subtypename = $subname["subtype"];}
}
.
.
.
.
.
.
.
$addresses = "";
If (!empty($typename) && !empty($subtypename) && !empty
($descriptionname) && !empty($phonenumber)&& !empty
($website1) ){
$add = "SELECT * FROM address where addressid = '$address[$j]'";
$address = mysql_query($add);
while ($adds = mysql_fetch_array($address))
{$addresses = $adds["address"];}
}
Here is the result of these coding
{GSMSMS}{}{}Maklumat Am(Terminal Bas Kuala Lumpur-Kuala Lumpur-Pekeliling):06-762 0000
WEBSITE:not available
ADDRESS:Stesen Bas Pekeliling, Off Jalan Tun Razak, 50400 KL
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
GSMSMS}{}{}Maklumat Am(Terminal Bas Kuala Lumpur-Kuala Lumpur-Puduraya):09-622 1424
WEBSITE:not available
ADDRESS:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
{GSMSMS}{}{}Maklumat Am(Terminal Bas Kuala Lumpur-Kuala Lumpur-Perhentian Bas Klang):03-2698 0377
WEBSITE:not available
ADDRESS:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Note that from the result, address only appear once..why it happen? can somebody show me how to resolve it?
pls somebody help me since i'm quite new to php..