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
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jan 30, 2004 2:11 pm
Oke.. some of you might have seen this from database.. however its no longer a database question i guess.
i made some changes in the script
Code: Select all
while ($row = mysql_fetch_array($result))
// before this was if ($row = mysql_fetch_array($result))
// which cuases it not to fetch all rows
which gave me this error.
Parse error: parse error, unexpected T_ELSE in xml.php on line 46
So now i am stuck on how to change the Else statement in line 46
compleet script
Code: Select all
$result = mysql_query($query) or die (mysql_error());
$num = mysql_num_rows($result);
if ($num != 0)
{
$file= fopen("resulta.xml", "w");
$_xml ="<?xml version="1.0" encoding="UTF-8"?>\r\n";
$_xml .="<Caudat_xml>\r\n";
while ($rows = mysql_fetch_array($result))
{
$_xml .="\t<num_paquete>="" . $rows["Paqnr"] . "">\r\n";$_xml .="\t</num_paquete>\r\n";
$_xml .="\t<empresa>="" . $rows["Empresa"] . "">\r\n";$_xml .="\t</empresa>\r\n";
$_xml .="\t<codigo>="" . $rows["Codigo"] . "">\r\n";$_xml .="\t</codigo>\r\n";
$_xml .="\t<envio>="" . $rows["Envio"] . "">\r\n";$_xml .="\t</envio>\r\n";
$_xml .="\t<desde>="" . $rows["Desde"] . "">\r\n";$_xml .="\t</desde>\r\n";
$_xml .="\t<peso_total>="" . $rows["Peso_Total"] . "">\r\n";$_xml .="\t</peso_total>\r\n";
$_xml .="\t<peso>="" . $rows["Peso"] . "">\r\n";$_xml .="\t</peso>\r\n";
$_xml .="\t<valor>="" . $rows["Valor"] . "">\r\n";$_xml .="\t</valor>\r\n";
$_xml .="\t<codigo_env>="" . $rows["Codigo_Env"] . "">\r\n";$_xml .="\t</codigo_env>\r\n";
$_xml .="\t<informacion>="" . $rows["Information"] . "">\r\n";$_xml .="\t</informacion>\r\n";
//$_xml .="\t<dato="" .$hoy. "">\r\n";$_xml .="\t</dato>\r\n";
}
else //-------------> line 46
{
$_xml .="\t<Query_Empty>="No Resulta">\r\n";
$_xml .="\t</Query_Empty>\r\n";
}
}
$_xml .="</Caudat_xml>";
fwrite($file, $_xml);
fclose($file);
echo "XML formato list. <a href="resulta.xml">Por Aqui el formato XML.</a>";
?>
How should i do this? any suggestions![/i]
Last edited by
ol4pr0 on Fri Jan 30, 2004 3:08 pm, edited 1 time in total.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Jan 30, 2004 2:13 pm
if(mysql_num_rows($result) > 0){
while($rows = mysql_fetch_array($result)){
.....
}
} else {
//there were no rows returned
}
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jan 30, 2004 2:21 pm
I wished that did the trick
unless i did some wrong
Code: Select all
<?
$result = mysql_query($query) or die (mysql_error());
$num = mysql_num_rows($result);
$file= fopen("resulta.xml", "w");
$_xml ="<?xml version="1.0" encoding="UTF-8"?>\r\n";
$_xml .="<Caudat_xml>\r\n";
if(mysql_num_rows($result) > 0){
while($rows = mysql_fetch_array($result))
{?>
Unipus
Forum Contributor
Posts: 409 Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA
Post
by Unipus » Fri Jan 30, 2004 2:23 pm
Yeah, you didn't close your original IF statement.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Jan 30, 2004 2:23 pm
Hard to tell from that snippet, need to see more
And if it doesn't work, maybe state what's happening, any errors etc...
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jan 30, 2004 2:29 pm
Error ocured line 47 now.
Code: Select all
$file= fopen("resulta.xml", "w");
$_xml ="<?xml version="1.0" encoding="UTF-8"?>\r\n";
$_xml .="<Caudat_xml>\r\n";
if(mysql_num_rows($result) > 0){
while($rows = mysql_fetch_array($result))
{
$_xml .="\t<num_paquete>="" . $rows["Paqnr"] . "">\r\n";$_xml .="\t</num_paquete>\r\n";
$_xml .="\t<empresa>="" . $rows["Empresa"] . "">\r\n";$_xml .="\t</empresa>\r\n";
$_xml .="\t<codigo>="" . $rows["Codigo"] . "">\r\n";$_xml .="\t</codigo>\r\n";
$_xml .="\t<envio>="" . $rows["Envio"] . "">\r\n";$_xml .="\t</envio>\r\n";
$_xml .="\t<desde>="" . $rows["Desde"] . "">\r\n";$_xml .="\t</desde>\r\n";
$_xml .="\t<peso_total>="" . $rows["Peso_Total"] . "">\r\n";$_xml .="\t</peso_total>\r\n";
$_xml .="\t<peso>="" . $rows["Peso"] . "">\r\n";$_xml .="\t</peso>\r\n";
$_xml .="\t<valor>="" . $rows["Valor"] . "">\r\n";$_xml .="\t</valor>\r\n";
$_xml .="\t<codigo_env>="" . $rows["Codigo_Env"] . "">\r\n";$_xml .="\t</codigo_env>\r\n";
$_xml .="\t<informacion>="" . $rows["Information"] . "">\r\n";$_xml .="\t</informacion>\r\n";
//$_xml .="\t<dato="" .$hoy. "">\r\n";$_xml .="\t</dato>\r\n";
}
else
{ // ---> line 47
$_xml .="\t<Query_Empty>="No Resulta">\r\n";
$_xml .="\t</Query_Empty>\r\n";
}
}
$_xml .="</Caudat_xml>";
fwrite($file, $_xml);
fclose($file);
echo "XML formato list. <a href="resulta.xml">Por Aqui el formato XML.</a>";
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Jan 30, 2004 2:31 pm
Your doing
if(){
while(){
} else {
}
}
you need to be doing
if(){
while(){
}
} else {
}
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Fri Jan 30, 2004 2:33 pm
Unipus wrote: Yeah, you didn't close your original IF statement.
Code: Select all
} // by adding this.. i needed to delete the line 53 }
} else {
you were right about that one..
Close it one time to many
Code: Select all
else
{
$_xml .="\t<Query_Empty>="No Resulta">\r\n";
$_xml .="\t</Query_Empty>\r\n";
}
// { line 53
$_xml .="</Caudat_xml>";
Now it does work