RyanSF07 Posted January 14, 2011 Share Posted January 14, 2011 Hello, I'm getting an "unexpected T-variable" error on the $all = SELECT line. I've gut this down to nothing. What is throwing the error? while($row = mysql_fetch_array($result)) { $all = "SELECT * FROM video ORDER BY id"; $result = mysql_query($all); etc. etc } thank you for your help, Ryan Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/ Share on other sites More sharing options...
mikosiko Posted January 14, 2011 Share Posted January 14, 2011 maybe you want to do (no a complete code... just to show you an example): $all = "SELECT * FROM video ORDER BY id"; $result = mysql_query($all); while($row = mysql_fetch_array($result)) { etc. etc } Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159148 Share on other sites More sharing options...
RyanSF07 Posted January 14, 2011 Author Share Posted January 14, 2011 Same thing -- unexpected T-variable Here's the code. I'm trying to pull content from the database and place it in an HTML table. Thank you for your help! function imageResize($width, $height, $target) { if ($width > $height) { $percentage = ($target / $width); } else { $percentage = $height == 0? 0 : $target / $height; } $width = round($width * $percentage); $height = round($height * $percentage); return "width=\"$width\" height=\"$height\""; } while($row = mysql_fetch_array($result)) { $rs = "SELECT * FROM video ORDER BY id"; $num = mysql_numrows($result); $result = mysql_query($rs); $tdcount = 1; $numtd = 4; // number of cells per row $table_content .= "<table>"; while($row = mysql_fetch_array($result)<$num) { if ($tdcount == 1) $table_content .= "<tr>"; $table_content .= "<td><p><a href='view.php?id=" . $row['id'] . "'><img src='http://www.site.com/images/". $row['photo'] ."' " . imageResize($resized[0], $resized[1], 100) ."></a><br>" . $row['title'] . "<br>views " . $row['counter'] . "<br>". ThumbsUp::item($row['id'])->template('mini_thumbs')->format('{UP}↑↓{DOWN}') ."</td>"; if ($tdcount == $numtd) { $table_content .= "</tr>"; $tdcount = 1; } else { $tdcount++; } } //close table if ($tdcount!= 1) { while ($tdcount <= $numtd) { $table_content .= "<td> </td>"; $tdcount++; } $table_content .= "</tr>"; } $table_content .= "</table>"; include_once ("template_test.inc"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159159 Share on other sites More sharing options...
mikosiko Posted January 14, 2011 Share Posted January 14, 2011 the error that you are getting normally is caused for an unmatched ( or { or ; check that... in also fix the error that already I did mention. in addition... you have more errors in your code... like p.e, the while usage is fubar... so please review your code logic Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159168 Share on other sites More sharing options...
Pikachu2000 Posted January 14, 2011 Share Posted January 14, 2011 Your code is full of non-displaying characters. They're showing up in my phone's browser . . . Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159169 Share on other sites More sharing options...
RyanSF07 Posted January 14, 2011 Author Share Posted January 14, 2011 Thank you Pikachu. I removed them. Now the error I'm getting is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (1st line in code snip below). My select query is abbreviated here -- but I don't think that's the problem. Thank you again for your help. while($row = mysql_fetch_array($result)) { $rs = "SELECT * video ORDER BY id DESC"; $result = mysql_query($rs); $num = mysql_numrows($result); $tdcount = 1; $numtd = 4; // number of cells per row $table_content .= "<table>"; while($row = mysql_fetch_array($result)<$num) { if ($tdcount == 1) $table_content .= "<tr>"; $table_content .= "<td><p><a href='view.php?id=" . $row['id'] . "'><img src='http://www.site.com/images/". $row['photo'] ."' " . imageResize($resized[0], $resized[1], 100) ."></a><br>" . $row['title'] . "<br>views " . $row['counter'] . "<br>". ThumbsUp::item($row['id'])->template('mini_thumbs')->format('{UP}↑↓{DOWN}') ."</td>"; if ($tdcount == $numtd) { $table_content .= "</tr>"; $tdcount = 1; } else { $tdcount++;} } //close table if ($tdcount!= 1) { while ($tdcount <= $numtd) { $table_content .= "<td> </td>"; $tdcount++; } $table_content .= "</tr>"; } $table_content .= "</table>"; } include_once ("template_test.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159178 Share on other sites More sharing options...
Pikachu2000 Posted January 14, 2011 Share Posted January 14, 2011 The query string is missing the FROM Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159187 Share on other sites More sharing options...
RyanSF07 Posted January 14, 2011 Author Share Posted January 14, 2011 You and mikosiko are awesome. Thank you so much for your help. Excluding the FROM was my mistake -- I shouldn't have abbreviated the Select query. Miko -- I ditched that unneeded While query. Thank you. Here's what I have now with my full Select query -- no errors -- but nothing displayed either. Any ideas? $rs = "SELECT video.id, title, description_text, category_text, level_text, pass_text, user_name, DATE_FORMAT(date, '%M %D, %Y') as date FROM video, registered_users WHERE video.user_id = registered_users.id AND video.category_text = 'English' AND video.level_text = 'high-intermediate' AND video.pass_text = 'featured' ORDER BY id DESC"; $result = mysql_query($rs); $tdcount = 1; $numtd = 4; // number of cells per row $table_content .= "<table>"; while($row = mysql_fetch_array($result)<$numtd) { if ($tdcount == 1) $table_content .= "<tr>"; $table_content .= "<td><p><a href='view.php?id=" . $row['id'] . "'><img src='http://www.site/images/". $row['photo'] ."' " . imageResize($resized[0], $resized[1], 100) ."></a><br>" . $row['title'] . "<br>views " . $row['counter'] . "<br>". ThumbsUp::item($row['id'])->template('mini_thumbs')->format('{UP}↑↓{DOWN}') ."</td>"; if ($tdcount == $numtd) { $table_content .= "</tr>"; $tdcount = 1; } else { $tdcount++;} } //close table if ($tdcount!= 1) { while ($tdcount <= $numtd) { $table_content .= "<td> </td>"; $tdcount++; } $table_content .= "</tr>"; } $table_content .= "</table>"; include_once ("template_test.php"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159192 Share on other sites More sharing options...
mikosiko Posted January 14, 2011 Share Posted January 14, 2011 add this 2 lines at the beginning of your code (after <?php) to enable display of errors error_reporting(E_ALL); ini_set("display_errors", true); now... what are you trying to do here? ... while($row = mysql_fetch_array($result)<$numtd) { and post your complete code... the portion that you posted has unmatched {} Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159482 Share on other sites More sharing options...
Maq Posted January 14, 2011 Share Posted January 14, 2011 Formatting your code would also help greatly. Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159484 Share on other sites More sharing options...
RyanSF07 Posted January 14, 2011 Author Share Posted January 14, 2011 Thank you, MikoSiko. "now... what are you trying to do here? ... while($row = mysql_fetch_array($result)<$numtd) {" Taking a fresh look there -- I deleted <$numtd and everything works. Thanks again for pointing that out. Quote Link to comment https://forums.phpfreaks.com/topic/224378-unexpected-t-error/#findComment-1159571 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.