Jump to content

can anyone tell me why i can't see the last forum? Oo...


rootKID

Recommended Posts

Hello W3S!

 

Im currently trying to make a forum of a sort... but not going so good.

 

The 2 pictures i have uploaded shows the forums and the forum-database.

 

Im also trying to "add" in a min-user-class for users to actually SEE/READ/WRITE the forum each by each..

i think that is where i have my problem, b-coz as you see in the forum picture i dont get any forums coming out.. even tho i actually have at least one in the database added up to it.

 

Here is my code:

<?php$overforum_res = sql_query("SELECT * FROM overforums ORDER BY of_id");while($of_arr = mysql_fetch_assoc($overforum_res)){	// User has reading rights. (if BIGGER or EQUAL to!)	if($CURUSER['u_FK_uc_id'] >= $of_array['of_u_class_read_min'])	{		$HTMLOUT .= "<table class='overforum_table_holder' border='0' cellpadding='0' cellspacing='0'>";			//======================================			// OVERFORUMS			//======================================						$HTMLOUT .= "<tr class='overforum_tr_holder'>";				// Forum Name				$HTMLOUT .= "<td class='overforum_name'>";					$HTMLOUT .= "<a href='forums.php?f_action=overforumview&overforum_id=".$of_arr['of_id']."'>";						$HTMLOUT .= $of_arr['of_name'];					$HTMLOUT .= "</a>";				$HTMLOUT .= "</td>";								// Last Post & Last Reply				$HTMLOUT .= "<td class='overforum_last_post_and_reply'>";					$HTMLOUT .= "Sidste Indlæg";				$HTMLOUT .= "</td>";								// Topic(s) Count By Forums				$HTMLOUT .= "<td class='overforum_topics'>";					$HTMLOUT .= "Emner";				$HTMLOUT .= "</td>";								// Answer(s) Count By Topic				$HTMLOUT .= "<td class='overforum_posts'>";					$HTMLOUT .= "Indlæg";				$HTMLOUT .= "</td>";			$HTMLOUT .= "</tr>";						//======================================			// FORUMS			//======================================						$f_res = sql_query("SELECT * FROM forums WHERE f_FK_of_id = ".$of_arr['of_id']." ORDER BY f_id");			$f_array = mysql_fetch_assoc($f_res);						while($f_arr = mysql_fetch_assoc($f_res))			{				// User has reading rights. (if BIGGER or EQUAL to!)				if($CURUSER['u_FK_uc_id'] >= $f_array['f_u_class_read_min'])				{					$HTMLOUT .= "<tr class='forum_tr_holder'>";												// Forum Name						$HTMLOUT .= "<td class='forum_name'>";							$HTMLOUT .= "<a href='forums.php?f_action=viewforum&forum_id=".$f_arr['f_id']."'>";								$HTMLOUT .= $f_arr['f_name'];							$HTMLOUT .= "</a>";						$HTMLOUT .= "</td>";												// Forum Last Post & Last Reply						$HTMLOUT .= "<td class='forum_last_post_and_reply'>";							//If bigger than 20 letters OR equal...							if(strlen("Pasta gratin for fattigrøve eller travle forældre/unge (nok til 4 personer)") >= 40)							{								$HTMLOUT .= "<span class='forum_float_left'>";									$HTMLOUT .= "".substr("Pasta gratin for fattigrøve eller travle forældre/unge (nok til 4 personer)", 0, 35)."...";								$HTMLOUT .= "</span>";																$HTMLOUT .= "<span class='forum_float_right'>";									//$HTMLOUT .= "Af Hyperion, 15 timer siden";									$HTMLOUT .= "Af Hyperion";								$HTMLOUT .= "";							}							else							{								$HTMLOUT .= "<span class='forum_float_left'>";									$HTMLOUT .= "Pasta gratin for fattigrøve eller travle forældre/unge (nok til 4 personer)";								$HTMLOUT .= "</span>";																$HTMLOUT .= "<span class='forum_float_right'>";									//$HTMLOUT .= "Af Hyperion, 15 timer siden";									$HTMLOUT .= "Af Hyperion";								$HTMLOUT .= "";							}						$HTMLOUT .= "</td>";												// Forum Topics						$HTMLOUT .= "<td class='forum_topics'>";							//$HTMLOUT .= number_format("10000000000");							$HTMLOUT .= number_format(get_forum_topics_row_count("topics", "WHERE ft_FK_f_id = " . $f_arr['f_id']));						$HTMLOUT .= "</td>";												// Forum Posts						$HTMLOUT .= "<td class='forum_posts'>";							//$HTMLOUT .= number_format("10000000000");							$HTMLOUT .= number_format(get_forum_posts_row_count("posts", "WHERE fp_FK_ft_id = " . $f_arr['f_id']));						$HTMLOUT .= "</td>";					$HTMLOUT .= "</tr>";				} // USER RIGHTS END!			} // WHILE LOOP FORUMS END!		$HTMLOUT .= "</table>";	} // USER READING RIGHTS END! ( IF / ELSE )} // OVERFORUMS WHILE-LOOP END!?>

please take note the setup is in Danish, but never the less the same thing.

 

I hope you/someone can help as always :)

 

-rootKID

post-86913-0-58414400-1395507092_thumb.png

post-86913-0-01537500-1395507094_thumb.png

Link to comment
Share on other sites

When you call mysql_fetch_assoc it moves the pointer ahead and you won't get data from that rown anymore. So in the following code you're not printing any data from the first row

$f_array = mysql_fetch_assoc($f_res);while($f_arr = mysql_fetch_assoc($f_res))
Link to comment
Share on other sites

Ohh.. well, i should have seemed that one coming x).

 

I just thought i could use same SQL at 2 places Oo... seems not Oo..

This answer actually answers alot of my other problems i have faced in the past! Thanks for the information dude! :D

 

-rootKID

Link to comment
Share on other sites

hmm.. i do understand what you are saying JSG... but i dont use mysql_query all the time... i can use it easily!

 

The sql_query is a function i have made like this:

function sql_query($query){	//$result = mysql_query($query);	$result = mysql_query($query) or sqlerr(__FILE__, __LINE__);		return $result;}

so if i wish to switch to, lets say mysqli it's affecting ALL my rows/sql lines :)...

so when i put online, i will switch to mysqli as you said, was also my plan to begin with.. i always for some reason just code in mysql.. just a force of habbit i assume x)

Link to comment
Share on other sites

so if i wish to switch to, lets say mysqli it's affecting ALL my rows/sql lines

No, it's not going to work like that. You're still using the mysql extension when you're using functions like mysql_num_rows, mysql_fetch_assoc, etc. You need to change all of those, not just mysql_query. If you really want portability then use PDO. Then if you switch databases you only need to change the connect string to use the new driver. Right now, using the mysql extension, you're digging your hole deeper with every new page you make.Consider this, from the overview for the mysqli extension:

Note:If you are using MySQL versions 4.1.3 or later it is strongly recommended that you use the mysqli extension instead.

MySQL version 4.1.3 came out in 2004, that version is 10 years old. PHP has been trying to get you to use mysqli for the last 10 years. The latest version of MySQL is 5.7. You're using a MySQL API that was introduced in PHP version 2, in 1997. There are people actually writing PHP code who are younger than the mysql extension. It's probably time that you forget it ever existed and move up to something current. There are plenty of reasons why that extension is deprecated and slated for removal from PHP (no prepared statements, no transactions, no stored procedures, etc).http://www.php.net/manual/en/mysqlinfo.api.choosing.phpIt's time to start using prepared statements and letting the API protect the database. The mysql extension does not protect the database.
Link to comment
Share on other sites

it's not b-coz i dont want to! It's because i keep thinking it will kinda "disable" the whole stuff.. the way it's working and coded all together...

right now im using some stuff i have developed myself, like template/design system that makes it EASY for me to make a design/template for a customer to keep them happy for the support i give them for free once in a while, and pages that generated from each template system i release each time...

 

it's kinda complicated to explain the way i have builded it all together, but if it's not affecting the way i have builded the whole thing up so far, i wont have a problem with it and would like to change it right away x)..

Edited by rootKID
Link to comment
Share on other sites

There is zero reason to use the mysql extension, for anything. It cannot do a single thing that mysqli or PDO cannot do. Are you going to have to rewrite all of your code? Yeah, you need to rewrite everything that uses the database, but that's what happens when you use really old things. If you're thinking that you don't want to do that now, or it's too much work, just remember that the more you use mysql, the more work you are making for yourself later. You can either take the time to do it right, or make the time to do it over. Considering that the mysql extension is currently deprecated and scheduled to be removed from PHP, there's going to come a time when you have to change everything because your code won't even work with whatever version of PHP has mysql removed. So might as well start now, and do it right.It's not necessarily your fault, there are still a ton of tutorials online that try to teach people PHP by using the mysql extension, but there's just no reason to use it. Those tutorials should not be teaching it. It took W3schools a while to remove it, but they don't even have a reference for mysql anymore, the reference is for mysqli:http://www.w3schools.com/php/php_ref_mysqli.asp

Link to comment
Share on other sites

but does it makes a difference? I mean the way i use mysqli/mysql?... i saw that i had to use some sort of OOP to use it.. " NEW / -> / .... "...

 

Seems eazy, but dont i only need to re-write the "mysql" lines to "mysqli"?... just thinking about if i need to change more than that.. to use them properly, if you know what i mean?

Link to comment
Share on other sites

The mysqli extension has an object-oriented interface and also a procedural interface. You don't need to use objects. You should, because they're easier, but you don't need to. If you want to call functions like with the mysql extension you can do that, although your code will probably be longer.

Seems eazy, but dont i only need to re-write the "mysql" lines to "mysqli"?

No, it's more than just a name, it's the way you use it. With mysqli you should be using prepared statements any time you have a query that contains user-supploed data, for example. This describes how to use prepared statements:http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.phpThe mysql extension does not support prepared statements, so it's not just changing a bunch of function names. This is a new feature that the old version does not support. You should not be using mysqli_real_escape_string, you should use prepared statements instead.
Link to comment
Share on other sites

what i ment by the last post, was that i basicly have trouble understanding the use of it.. i mean, is it ALOT that is changed in the mysqli use base? In other words, is it ALOT more different to use than mysqli... i dont know how else to explain myself with this.. i will try! However i can't promise i understand all of it.. maybe some of it, but all other commands i still dont understand, and i might need some of them to re-place the old ones for like the forum i am about to build for the customer and all that..

 

Even the menu on the website is dynamicly build up... so... i suppose i can call for help if my website is broken.. as always hehe? ;)...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...