Jump to content

[SOLVED] Functions


Steve Angelis

Recommended Posts

I am a nooby to functions so here is what I am trying to do.

 

I am getting all the information from a database, easy.  I get it to show the data.  Easy

The problem is I want it to show a max of 9 entries and then go to the next line, but I am stuck.  Here is my code.

 

 

 

				function ribbons9($ribbon_nums)
				if (mysql_numrows>9)
					{
					echo $content['medal_id'];
					}

 

I got that far then I got stuck as hell.  Does anyone have any ideas?  All I want is for it to show the medal_id till there are 9 in a row, then go to the next row and show the next 9 etc till there are none left.

Link to comment
Share on other sites

	$ribbon_select = mysql_query('select * from phpbb_medal_user');
			$ribbon_result = mysql_query($ribbon_select) or die("$ribbon_select does not make any sence;<br>" . mysql_error());
$x = 0;
while ($list = mysql_fetch_assoc($ribbon_result)) {
   echo $list['medal_id'];
   echo (($x % 9) == 0) ? "<br />" : " ";
}

 

There is the complete with table and what not.

 

I get this error:

 

Resource id #13 does not make any sence;

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #13' at line 1

Link to comment
Share on other sites

Inside the mysql function at the last part you could put "LIMIT 0,9" and that would retrieve rows 1,2,3,4,5,6,7,8,9. And keep doing that.

Sample :

 

$_start=0;
$_current=0;

$_one=mysql_query("SELECT * FROM place");
$_onenum=mysql_num_rows($_one);

do {
  $_two=mysql_query("SELECT * FROM place LIMIT ".$_start.",9");

  while($_rows=mysql_fetch_array($_two)) {
    echo($_rows["row"]);
  }

  $_start+=9;
  $_current+=9;
  echo("<br /><br />");
}
while ($_onenum>$_current);

 

I think that should work, but I didn't test it. There is probably an easier way anyway.

Link to comment
Share on other sites

	$ribbon_select = mysql_query('select * from phpbb_medal_user');
			$ribbon_result = mysql_query($ribbon_select) or die("$ribbon_select does not make any sence;<br>" . mysql_error());
$x = 0;
while ($list = mysql_fetch_assoc($ribbon_result)) {
   echo $list['medal_id'];
   echo (($x % 9) == 0) ? "<br />" : " ";
}

 

There is the complete with table and what not.

 

I get this error:

 

Resource id #13 does not make any sence;

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #13' at line 1

 

you're trying to run a query on a result source from another query.  remove the mysql_query from $ribbon_select, just put it in quotes as a query string:

$ribbon_select = 'select * from phpbb_medal_user';
$ribbon_result = mysql_query($ribbon_select) or die("$ribbon_select does not make any sence;<br>" . mysql_error());
$x = 0;
while ($list = mysql_fetch_assoc($ribbon_result)) {
   echo $list['medal_id'];
   echo (($x % 9) == 0) ? "<br />" : " ";
}

Link to comment
Share on other sites

oh and I forgot to increment $x :

$ribbon_select = 'select * from phpbb_medal_user';
$ribbon_result = mysql_query($ribbon_select) or die("$ribbon_select does not make any sence;<br>" . mysql_error());
$x = 0;
while ($list = mysql_fetch_assoc($ribbon_result)) {
   echo $list['medal_id'];
   echo (($x % 9) == 0) ? "<br />" : " ";
   $x++;
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.