sabo86 Posted September 14, 2008 Share Posted September 14, 2008 I am trying to display my results, I tried this way: echo "<p>Number of records found: ".$num_results."</p>"; while ($row = mysql_fetch_array($result)){ $Model.="<td>$row['Model']</td>"; $Description.="<td>$row['Description']</td>"; $Category.="<td>$row['Category']</td>"; $Image.="<td>$row['Picture']</td>"; } for ($i=0; $i <$num_results; $i++) { <table> <tr><td>echo "<p><strong>.($i+1).".Model</td><?=$Model</tr> <tr><td>echo "<p><strong>.($i+1).".Description</td><?=$Description</tr> <tr><td>echo "<p><strong>.($i+1).".Category</td><?=$Category</tr> <tr><td>echo "<p><strong>.($i+1).".Picture</td><?=$Image</tr> } but i got this error: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 76 What's the problem? Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/ Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 for ($i=0; $i <$num_results; $i++) { ?> <table> <tr><td><?php echo "<p><strong>".($i+1)."Model"; ?></td><?=$Model?></tr> <tr><td><?php echo "<p><strong>".($i+1)."Description"; ?></td><?=$Description?></tr> <tr><td><?php echo "<p><strong>".($i+1)."Category"; ?></td><?=$Category?></tr> <tr><td><?php echo "<p><strong>".($i+1)."Picture"; ?></td><?=$Image?></tr> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641050 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 Didn't work error: Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 77 Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641055 Share on other sites More sharing options...
JasonLewis Posted September 14, 2008 Share Posted September 14, 2008 Try wildteens code again, it was edited. You are not echoing your data properly, what wildteen has done is closed of PHP so that you can display HTML, then opened it again. Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641056 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 it didn't work as well.. the same error! Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641057 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 echo "<p>Number of records found: ".$num_results."</p>"; while ($row = mysql_fetch_array($result)) { $Model .= '<td>'.$row['Model'].'</td>'; $Description .= '<td>'.$row['Description'].'</td>'; $Category .= '<td>'.$row['Category'].'</td>'; $Image .= '<td>'.$row['Picture'].'</td>'; } for ($i=0; $i <$num_results; $i++) { ?> <table> <tr><td><?php echo "<p><strong>".($i+1)."Model"; ?></td><?=$Model?></tr> <tr><td><?php echo "<p><strong>".($i+1)."Description"; ?></td><?=$Description?></tr> <tr><td><?php echo "<p><strong>".($i+1)."Category"; ?></td><?=$Category?></tr> <tr><td><?php echo "<p><strong>".($i+1)."Picture"; ?></td><?=$Image?></tr> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641058 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 OK I tried this one, the results are as following: Notice: Undefined variable: field in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 54 Number of records found: 4 Notice: Undefined variable: Model in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 77 Notice: Undefined variable: Description in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 78 Notice: Undefined variable: Category in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 79 Notice: Undefined variable: Image in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 80 1Model 1Description 1Category 1Picture 2Model 2Description 2Category 2Picture 3Model 3Description 3Category 3Picture 4Model 4Description 4Category 4Picture Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641061 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 The last four is caused by the use of the concatenation operator (.=), add $Model = $Description = $Category = $Image = null before your while loop Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641066 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 ok i got Fleifel Notice: Undefined variable: field in C:\Program Files\EasyPHP 2.0b1\www\test fleifel\results.php on line 54 Number of records found: 4 1Model 1Description 1Category 1Picture 2Model 2Description 2Category 2Picture 3Model 3Description 3Category 3Picture 4Model 4Description 4Category 4Picture But I am not getting the results from the database.. just the atribute names... Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641067 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 Now my code is: $Model .= '<td>'.$row['Model'].'</td>'; $Description .= '<td>'.$row['Description'].'</td>'; $Category .= '<td>'.$row['Category'].'</td>'; $Image .= '<td>'.$row['Picture'].'</td>'; } for ($i=0; $i <$num_results; $i++) { ?> <table> <tr><td><?php echo "<br><p><strong>".($i+1).". Model:"; ?></td><?=$Model?></tr> <tr><td><?php echo "<strong> Description:"; ?></td><?=$Description?></tr> <tr><td><?php echo "<strong> Category:"; ?></td><?=$Category?></tr> <tr><td><?php echo "<strong> Picture:"; ?></td><?=$Image?></tr> <?php } and results are like: Number of records found: 4 1. Model: Description: Category: Picture: 2. Model: Description: Category: Picture: 3. Model: Description: Category: Picture: 4. Model: Description: Category: Picture: How can I get the records in these attributes? Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641071 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 I think you should explain what you're trying to do. I'm not understanding you. Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641074 Share on other sites More sharing options...
kenrbnsn Posted September 14, 2008 Share Posted September 14, 2008 You are using "short tags" -- "<?=". Replace the "<?=" with "<?php echo ". Ken Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641076 Share on other sites More sharing options...
sabo86 Posted September 14, 2008 Author Share Posted September 14, 2008 Ok.. well.. I want simply to display the database's records in a neat table so that it would be compatible with my layout that i will design later on Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641078 Share on other sites More sharing options...
kenrbnsn Posted September 14, 2008 Share Posted September 14, 2008 The code you've posted will not display what you think it will. Try something like this: <?php echo "<p>Number of records found: ".$num_results."</p>"; $i = 1; echo "<table>\n"; while ($row = mysql_fetch_assoc($result)) { echo '<tr><td style="font-weight:bold">' . $i . ' Model</td><td>' . $row['Model'] . '</td></tr>'; echo '<tr><td style="font-weight:bold">' . $i . ' Description</td><td>' . $row['Description'] . '</td></tr>'; echo '<tr><td style="font-weight:bold">' . $i . ' Category</td><td>' . $row['Category'] . '</td></tr>'; echo '<tr><td style="font-weight:bold">' . $i . ' Picture</td><td>' . $row['Picture'] . '</td></tr>'; $i++; } echo '</table>'; ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/124169-displaying-the-results/#findComment-641085 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.