Using PHP to pull data from MySQL [closed]

numoccurn

New Member
I created a few lines of code to pull data from mysql and output them as xml, then mark the records as read.Is there a better approach ? \[code\]$sql = "select message_id,service_id, msisdn, message_text from tb where message_status = 0 limit 10";$query = mysql_query($sql); if (mysql_num_rows($query) > 0){$xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<Records>\n"; while($row = mysql_fetch_array($query)){ $xml_output .= "<Record>\n"; $xml_output .= "<MessageId>".$row["message_id"]."</MessageId>\n"; $xml_output .= "<ServiceId>".$row["service_id"]."</ServiceId>\n"; $xml_output .= "<Msisdn>".$row["msisdn"]."</Msisdn>\n"; $xml_output .= "<Text>".$row["message_text"]."</Text>\n"; $xml_output .= "</Record>\n"; $sql2 = "update tb set message_status = 1 where message_id = ".$row["message_id"]; $query2 = mysql_query($sql2);}$xml_output .= "</Records>\n"; }else{$xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<Records/>\n"; }echo $xml_output;\[/code\]
 
Back
Top