Click to See Complete Forum and Search --> : More Complex Restructuring
AvisSoft
Oct 26th, 2004, 06:37 AM
Hi!
Here more complex resturcturing of data whihc i have totally failed to do.
Currently i get records from mysql in the following format:
id 1
desc 1
id 2
desc 2
id 3
desc 3
id 4
desc 4
id # and desc # are 1 record displayed in 2 lines. for eg. echo $a1[id];
echo "<br>\n";
echo $a1[desc];
now i want to have them using tables in the following format:
id 1 id 2
desc1 desc 2
id 3 id 4
desc3 desc 4
Is this possible ? very urgent please help i wasted my whole day and got nothing :( :mad:
Thanks!
ober0330
Oct 26th, 2004, 07:27 AM
If you couldn't figure this out from the previous question you asked, maybe you should consider a different career.
It's all about building strings and putting them together for your final result.
You can't build a table column by column. You have to build it row by row.
$i = 1;
while($row = mysql_fetch_array($result))
{
if($i == 1)
{
$str1 = "<tr><td>" . $row['id'] . "</td>";
$str2 = "<tr><td>" . $row['desc'] . "</td>";
}
else
{
echo $str1 . "<td>" . $row['id'] . "</td></tr>";
echo $str2 . "<td>" . $row['desc'] . "</td></tr>";
$i = 0;
}
$i++;
}
AvisSoft
Oct 26th, 2004, 07:47 AM
Hi ober!
I don't you scolding me..as i am newbie in php and you're an expert. Anyways i tried your code it works if there are even records in database like 0, 2, 4, 8 but if there are odd records in database like 1,3,5,7,9 then it eats up the last record it should display and only displays odd even records.
Can you help me fix this ?
Thanks!
ober0330
Oct 26th, 2004, 08:34 AM
Add the following after the code I gave you before (outside the while loop):
if($i == 2)
{
echo $str1 . "<td> </td></tr>";
echo $str2 . "<td>$nbsp;</td></tr>";
}
And I am far from an expert. It's all about logical thinking and picturing in your head what you want to accomplish. And this question was only a minor twist from the previous one. It shouldn't have been much of a stretch of the imagination. I apologize if I have offended you.
AvisSoft
Oct 26th, 2004, 08:39 AM
No problem! I appericiate your help! Thanks!
visualAd
Oct 26th, 2004, 08:51 AM
Ober, you weren't being offencive.
PHP.net has an excellent online manual with a functios able to accomplish almost any task, especially with regards to string manipulation. I was once a PHP newbie and in many ways I still ma, I make extensive use of the manual and very rarely need to post a question.
90% of the questions I answer in this forum a just links to the online manual with the function they need. We can all search the internet and find them ourselves and in some cases thats what I do for other people. My view is, if you want someone to write the code for you then send us money and we will be happy to assist. If you have a genuine problem which you are struggling to solve and have exhausted all avenues then post here and we are happy to assist for free :D
AvisSoft
Oct 26th, 2004, 08:59 AM
Hi visualAd
i am sorry to say that i have manual also..and it integreats into my php editor by pressing f1 i can get the help. but i don't think that questions i asked are mentioned anywhere in manual. Also i doubt if anyone has asked this type of question before on this forum i wrote whole of the code myself..i was just getting stuck at this one..which i asked.
I am sorry if i am asking too much. I must find some other place then. Sorry again!
Thanks!
ober0330
Oct 26th, 2004, 09:09 AM
No, you don't need to find another place. I get stuck on stuff too sometimes and I have no problem helping someone out of a jam. Sometimes you need a second pair of eyes.
However, if you are looking for a forum that has more traffic in terms of PHP help, check out www.phpfreaks.com I frequent there and questions are answered more quickly because there are more people to answer them.
AvisSoft
Oct 26th, 2004, 09:10 AM
Thanks ober! I appericiate this i will go and join there now! Thanks again!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.