Forum Moderators: coopster

Message Too Old, No Replies

Removing all names except one

Is it possible?

         

Jeigh

7:16 am on Jul 13, 2007 (gmt 0)

10+ Year Member



Hello,

If I extract a column from the database and the results are:

name1 - name2 - name3 - name4 - name5

Is it possible using PHP to delete everything to just leave one name, so if I wanted only name3 then I could store that in a variable called $name?

Thanks :)

mattclayb

7:51 am on Jul 13, 2007 (gmt 0)

10+ Year Member



hmm, why don't you just query that specific row & column?

Can you give more information about your table setup and what you are extracting 'name' against?

IndiaMaster

7:55 am on Jul 13, 2007 (gmt 0)

10+ Year Member



Hi,

If you got the result as "name1-name2-name3-name4-name5", then you can use the explode function to store the names in array and then browse through the array to keep the desired one.

If you got the names in different rows of the table then it is better to write query for that specific name.

Jeigh

8:00 am on Jul 13, 2007 (gmt 0)

10+ Year Member



All the names are stored in the one column, which is why I found it hard to just do a SQL query for it.

I'll go into a bit more detail here.

People can reccomend another users page, for example if I recommend name2 then in name2's row under 'recusers' it will record my name aswell as everyone elses who has already reccomended it. For this I used:

$insertname = "UPDATE users SET recusers='$vusername - $recusersr' WHERE username='$requsername'";
mysql_query($insertname);

$recusersr being all the names that were already there.

Would you be able to give me an example of that explode, or direct me to where I could find more information as I'm relatively knew to PHP and only know the basics.

Thanks.

[edited by: Jeigh at 8:02 am (utc) on July 13, 2007]

Jeigh

9:00 am on Jul 13, 2007 (gmt 0)

10+ Year Member



I've got the explode thing worked out now, I'll try doing the rest and let you guys know if it works.

Jeigh

9:23 am on Jul 13, 2007 (gmt 0)

10+ Year Member



Just a quick question, I'm using this to get the results I want:

$name['nameiwant'];

But it won't let me do this:

$name[$vusername];

$vusername being $_SESSION['username']

But if I use a variable just like $var = 'Jeigh'; it does work, just not with $_SESSION['username'].

How would I be able to get it so it displays the username of the session in $name[''].

Thanks again.

[edited by: Jeigh at 9:39 am (utc) on July 13, 2007]

Jeigh

1:30 pm on Jul 13, 2007 (gmt 0)

10+ Year Member



Hmm, I'll explain what I'm trying to do now.

If I use $name['george'] and there is no george there it will result in it being blank so I'll use:

if($sessionname == "")
{
*proceed with script*
}
else
{
echo "Sorry, you have already recommended this user"
}

So I need a way to get the sessions username to work in the
$name['$vusername'] but as I said it's not working for some reason. I'm assuming because that would be the same as $name['$_SESSION['username']'] which dosn't really look right (as far as I know :P)

Jeigh

2:15 am on Jul 14, 2007 (gmt 0)

10+ Year Member



Any ideas?

coopster

12:12 pm on Jul 16, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Did you start the session before you tried to access the session variable? If so, dump the $_SESSION superglobal to the browser so you can have a look through it's indexes and values.