No errors but doesn't work

Mysql, php thing

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 1030 Views - Last Post: 10 December 2009 - 01:45 AM Rate Topic: -----

#1 Johnson-php  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 14-November 09

No errors but doesn't work

Posted 09 December 2009 - 10:44 PM

Hi again, I have a shoutbox with few rows of message about 90 rows ever rows as the following

ID/Name/Message/Rank/IP X 90

In name has the logged in ID I mean the member id :
Name : 1 / member id
ID: Message ID

Now I would like to convert something like this
If the row as a $name = a member ID then Show the member name instate of Numbers
But I need to do this with few rows

$rs = mysql_query("SELECT name, message, staff FROM shoutbox ORDER BY id 
	 DESC LIMIT $start, $max") or die("Members query error!");
$name = $fetch['name'];


	while (list($name, $message, $staff) = mysql_fetch_row($rs)) {
		

		
echo "<div id='div-container'>";
echo "<div id='div-rank'>";
echo "$staff";
echo "</div>";
echo "<div id='div-name'>";
echo "<span class='by2'>";
function getUsername($name){
	$userQuery = mysql_query("select username from members where id=$name")or die(mysql_error());
	$userName = mysql_fetch_assoc($userQuery);
	return $userName['username'];
}
echo getUsername($name);
echo "</span>";
echo "</div>";
echo "<div id='div-message'>";
echo "<p class='content'>";
echo "$message";
echo "</p>";
echo "</div>";
echo "</div>";
echo "<br />";
	}

?>



Its not only 1 row! In the shoutbox table as few rows with few random name
So anyone know why this code isnt working ?
I just want to change the $name to a NAME from members table if the ID matches :)

This post has been edited by Johnson-php: 10 December 2009 - 01:32 AM


Is This A Good Question/Topic? 0
  • +

Replies To: No errors but doesn't work

#2 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: No errors but doesn't work

Posted 09 December 2009 - 10:59 PM

Why are you defining a function in the middle of your code? The syntax & layout of this code is extremely hard to follow. Cleaning up your code could show you a logic error.

I don't see an end bracket to your while loop.
Was This Post Helpful? 0
  • +
  • -

#3 Johnson-php  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 14-November 09

Re: No errors but doesn't work

Posted 09 December 2009 - 11:23 PM

View Postno2pencil, on 9 Dec, 2009 - 09:59 PM, said:

Why are you defining a function in the middle of your code? The syntax & layout of this code is extremely hard to follow. Cleaning up your code could show you a logic error.

I don't see an end bracket to your while loop.

I updated the post now its the complete code
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: No errors but doesn't work

Posted 09 December 2009 - 11:27 PM

View PostJohnson-php, on 10 Dec, 2009 - 12:23 AM, said:

now its the complete code

So you have no start PHP segment?
Was This Post Helpful? 0
  • +
  • -

#5 Johnson-php  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 14-November 09

Re: No errors but doesn't work

Posted 09 December 2009 - 11:31 PM

View Postno2pencil, on 9 Dec, 2009 - 10:27 PM, said:

View PostJohnson-php, on 10 Dec, 2009 - 12:23 AM, said:

now its the complete code

So you have no start PHP segment?

Yes I have but its on top
everything on top is ok
Was This Post Helpful? 0
  • +
  • -

#6 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: No errors but doesn't work

Posted 09 December 2009 - 11:33 PM

Here... I've done the grunt work for you :)

This will be much easier to read, & therefor easier to troubleshoot.

<?php

	function getUsername($name) {
		$userQuery = mysql_query("select username from members where id='1'")or die(mysql_error());
		$userName = mysql_fetch_assoc($userQuery);
		return $userName['username'];
	}

	$rs = mysql_query("SELECT name, message, staff FROM shoutbox ORDER BY id DESC LIMIT $start, $max") or die("Members query error!");
	$name = $fetch['name'];
	while (list($name, $message, $staff) = mysql_fetch_row($rs)) {
		echo "<div id='div-container'>";
		echo "<div id='div-rank'>";
		echo "$staff";
		echo "</div>";
		echo "<div id='div-name'>";
		echo "<span class='by2'>";

		if($access=="1") echo getUsername($name);
		
		else echo "$username";
		
		echo "</span>";
		echo "</div>";
		echo "<div id='div-message'>";
		echo "<p class='content'>";
		echo "$message";
		echo "</p>";
		echo "</div>";
		echo "</div>";
		echo "<br />";
	}

?>


Isn't that much easier to read?

Now... lets look at your function getUsername.... why are you passing in the argument $name, but then you never access it in the code? Lastly, where does the variable access get it's value? You're testing it to see if it equal a one, but where does it ever get it's value from?
Was This Post Helpful? 0
  • +
  • -

#7 Johnson-php  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 14-November 09

Re: No errors but doesn't work

Posted 09 December 2009 - 11:41 PM

Thanks so much but nothing changed :(
Nothing happens
Its just show the Messages from SHoutbox table but not the
Was This Post Helpful? 0
  • +
  • -

#8 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: No errors but doesn't work

Posted 09 December 2009 - 11:48 PM

All I've done is clean up the code...

Care to answer any of the questions I presented?

Also, when you reply, you don't need to include the entire text :)
Was This Post Helpful? 0
  • +
  • -

#9 Johnson-php  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 14-November 09

Re: No errors but doesn't work

Posted 10 December 2009 - 12:23 AM

View Postno2pencil, on 9 Dec, 2009 - 10:48 PM, said:

All I've done is clean up the code...

Care to answer any of the questions I presented?

Also, when you reply, you don't need to include the entire text :)

Sure but which questions ? :)
Was This Post Helpful? 0
  • +
  • -

#10 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: No errors but doesn't work

Posted 10 December 2009 - 12:44 AM

View Postno2pencil, on 10 Dec, 2009 - 12:33 AM, said:

Now... lets look at your function getUsername.... why are you passing in the argument $name, but then you never access it in the code? Lastly, where does the variable access get it's value? You're testing it to see if it equal a one, but where does it ever get it's value from?

Was This Post Helpful? 0
  • +
  • -

#11 Johnson-php  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 14-November 09

Re: No errors but doesn't work

Posted 10 December 2009 - 01:23 AM

View Postno2pencil, on 9 Dec, 2009 - 11:44 PM, said:

View Postno2pencil, on 10 Dec, 2009 - 12:33 AM, said:

Now... lets look at your function getUsername.... why are you passing in the argument $name, but then you never access it in the code? Lastly, where does the variable access get it's value? You're testing it to see if it equal a one, but where does it ever get it's value from?


Oh no I made an error on ACCESS thing :/
Thanks for warning me
I changed my code but I dont get results
and I dont get error messages :/
Was This Post Helpful? 0
  • +
  • -

#12 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: No errors but doesn't work

Posted 10 December 2009 - 01:27 AM

View PostJohnson-php, on 10 Dec, 2009 - 02:23 AM, said:

I changed my code but I dont get results
and I dont get error messages :/

& I can't help without seeing the updated code...
Was This Post Helpful? 0
  • +
  • -

#13 Johnson-php  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 14-November 09

Re: No errors but doesn't work

Posted 10 December 2009 - 01:32 AM

View Postno2pencil, on 10 Dec, 2009 - 12:27 AM, said:

View PostJohnson-php, on 10 Dec, 2009 - 02:23 AM, said:

I changed my code but I dont get results
and I dont get error messages :/

& I can't help without seeing the updated code...


Its on top ?
Thanks :)
Was This Post Helpful? 0
  • +
  • -

#14 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5348
  • View blog
  • Posts: 27,305
  • Joined: 10-May 07

Re: No errors but doesn't work

Posted 10 December 2009 - 01:37 AM

I'm actually trying to help you... but you just won't let me, will you?
Was This Post Helpful? 0
  • +
  • -

#15 Johnson-php  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 76
  • Joined: 14-November 09

Re: No errors but doesn't work

Posted 10 December 2009 - 01:42 AM

no2pencil
You can close this topic!
I found out the damm error ^^
Thanks very very much for your patient trying to help me :D :^:

This post has been edited by Johnson-php: 10 December 2009 - 01:42 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2