HDFilmMaker2112 Posted March 27, 2012 Share Posted March 27, 2012 The below is outputting: Array Fatal error: Unsupported operand types in /home/zyquo/public_html/area51entertainment.co/maintenance/home.php on line 28 So clearly $project_row_num is coming out as an array, and the multiplication is failing because its got a string not a number. I just don't see why it's getting an array out of $project_row_num. <?php $num_projects=15; $scroller_projects=""; require_once 'db_select.php'; $project_query_num="SELECT COUNT(*) FROM $tbl_name"; $project_result_num=mysql_query($project_query_num); $project_row_num=mysql_fetch_assoc($project_result_num); echo $project_row_num; //if($project_row_num <= $num_projects){ $project_query="SELECT * FROM $tbl_name"; $project_result=mysql_query($project_query); /*} else{ $project_query="SELECT * FROM $tbl_name WHERE project_release_date BETWEEN $start_date AND $end_date LIMIT 0,$num_projects"; $project_result=mysql_query($project_query); }*/ $i=1; while($project_row=mysql_fetch_array($project_result)){ extract($project_row); $scroller_projects.='<div class="project_entry" tabindex="'.$i.'" onclick="sndReq(\''.$project_id.'\');">Test</div>'; $i++; } if($project_row_num==""){ $films_row_num=$num_projects; } $scroller_width=$project_row_num*114; $content=' <div class="video_scroller_wrapper"> <div class="video" id="tabs"> </div> <div class="recentfilms_wrapper"> <div class="left_arrow"><img src="arrow_left.png" alt="Left" title="" class="arrow_left" onclick="jumpLeft(\'recentfilms\')" onmouseover="startScrollLeft(\'recentfilms\')" onmouseout="stopScroll()" /></div> <div id="recentfilms"> <div id="scroller" style="width: '.$scroller_width.'px;"> '.$scroller_projects.' </div> </div> <div class="right_arrow"><img src="arrow_right.png" alt="Left" title="" class="arrow_right" onclick="jumpRight(\'recentfilms\')" onmouseover="startScrollRight(\'recentfilms\')" onmouseout="stopScroll()" /></div> </div> </div> <div class="news_wrapper"> <div class="news"> <div class="news_title"><span class="category_title_text">Latest News</span></div> <div class="news_text"> <iframe src="http://www.indiegogo.com/project/widget/75876?a=9030" style="width: 224px; height: 429px; position: relative; left: 3px; top: 15px; border: 0px; overflow: hidden;"></iframe> </div> </div> </div> '; ?> Quote Link to comment https://forums.phpfreaks.com/topic/259788-array-being-output-unsure-why/ Share on other sites More sharing options...
HDFilmMaker2112 Posted March 27, 2012 Author Share Posted March 27, 2012 Just noticed that: $films_row_num=$num_projects; should be: $project_row_num=$num_projects; but that doesn't fix the issue. Quote Link to comment https://forums.phpfreaks.com/topic/259788-array-being-output-unsure-why/#findComment-1331481 Share on other sites More sharing options...
grim1208 Posted March 27, 2012 Share Posted March 27, 2012 mysql_fetch_assoc() returns an associative array. $project_result_num should be an int though ... Quote Link to comment https://forums.phpfreaks.com/topic/259788-array-being-output-unsure-why/#findComment-1331482 Share on other sites More sharing options...
HDFilmMaker2112 Posted March 27, 2012 Author Share Posted March 27, 2012 mysql_fetch_assoc() returns an associative array. $project_result_num should be an int though ... Right, that's what I figured; but I've tried mysql_fetch_array (which is clearly an array), and mysql_fetch_row which also returns an array. What should I be using here? Quote Link to comment https://forums.phpfreaks.com/topic/259788-array-being-output-unsure-why/#findComment-1331484 Share on other sites More sharing options...
trq Posted March 27, 2012 Share Posted March 27, 2012 If your looking for the number of rows returned it's mysql_num_rows. Quote Link to comment https://forums.phpfreaks.com/topic/259788-array-being-output-unsure-why/#findComment-1331487 Share on other sites More sharing options...
grim1208 Posted March 27, 2012 Share Posted March 27, 2012 If your looking for the number of rows returned it's mysql_num_rows. winner. what project is this for? Quote Link to comment https://forums.phpfreaks.com/topic/259788-array-being-output-unsure-why/#findComment-1331488 Share on other sites More sharing options...
HDFilmMaker2112 Posted March 27, 2012 Author Share Posted March 27, 2012 Got it with this: $project_query_num="SELECT COUNT(*) FROM $tbl_name"; $project_result_num=mysql_query($project_query_num); $project_row_num=mysql_fetch_row($project_result_num); $project_row_num=$project_row_num[0]; Was trying to stay away from using mysql_num_rows; wanted to do the counting entirely with MySQL. http://www.area51entertainment.co/maintenance Quote Link to comment https://forums.phpfreaks.com/topic/259788-array-being-output-unsure-why/#findComment-1331490 Share on other sites More sharing options...
PFMaBiSmAd Posted March 27, 2012 Share Posted March 27, 2012 Actually, since you are using a COUNT() in your query and you are not using an alias name, you would need to use mysql_fetch_row or mysql_fetch_array and then access the zero'th element of that array to get the count. Do you have php's error_reporting set to E_ALL so that all the errors php detects will be reported and displayed? You would be getting several notice and perhaps warnings from your code. Quote Link to comment https://forums.phpfreaks.com/topic/259788-array-being-output-unsure-why/#findComment-1331491 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.