Jump to content

Splitting (I think) a table field.


Siggles

Recommended Posts

I have a piece of code which takes the result of a column from a dbase and cuts off the first bit of text revealing the userid and then it matches the userid with the username and displays the username. Such as...

 

In the dbase - the to_address column data is

u_378

 

$userto=$row[to_address];

$userto2=str_replace("u_","","$userto");

 

and then there is a bit of script that macthes the resulting varaible to the username column. That all workfs fine. But what if there is more than one username listed in the dbase like follows...

 

u_378:u_384:u_135:u_358

 

Is there a way I can get all those seperate numbers and then display them using my current script..(all shown below)

 

$userto=$row[to_address];

  $userto2=str_replace("u_","","$userto");

 

   echo "<td valign=\"top\" width=\"10%\">$row[username]</td>";

   

   $results = mysql_query("SELECT username FROM phpbb3_users WHERE user_id = $userto2 ");

  while($row2 = mysql_fetch_array($results)){

   echo "<td valign=\"top\">$row2[username]</td>";

   }

 

I'm thinking I would need to use maybe 'split' and then a 'foreach'. I can;t get the syntax right!!

 

Thanks

Link to comment
Share on other sites

Still need help here.

 

So the database column to_address normally has...

u_358

 

And I use

str_replace("u_","","$userto");
to get the numbers from it. I then use

 

$results = mysql_query("SELECT username FROM phpbb3_users WHERE user_id = $userto2");

  while($row2 = mysql_fetch_array($results)){

  echo "<td valign=\"top\">$row2[username]</td>";

  }

 

to get the username that corresponds to the userid.

 

Now I need to take info like this....

 

u_2:u_358:u_135:u_378

 

split it somehow and print each seperate username stilll using the SELECT statement somehow.

 

So instead of Max it shows Max, John, Craig

 

Any ideas?

 

 

Link to comment
Share on other sites

Thanks, I finally got it to look how I wanted...

 

 echo "<tr>";
$var=$row[to_address];
$var = str_replace('u_', '', $var);
$var = str_replace(':', ',', $var);

echo "<td valign=\"top\" width=\"10%\">$row[username]</td><td valign=\"top\">";
$results = mysql_query("SELECT username FROM phpbb3_users WHERE user_id IN ($var)");
while($row2 = mysql_fetch_array($results)){
echo "$row2[username] ";
}
echo "</td>";

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.