Jump to content

Recommended Posts

I have a variable with several numbers in it, separated with a "." Is there a way to put these into separate variables.

e.g get "12.56.79.35.93.22" and turn it into.

 

"var1 = 12"

"var2 = 56"

"var3 = 79"

"var4 = 35"

 

and so on.

 

Something like for variable contains "." retrieve number and set another variable.

 

Thank you  :)

Link to comment
https://forums.phpfreaks.com/topic/68569-variables-and-separators/
Share on other sites

One last thing. How would I perform a for loop that searches a mysql database for each array entry. Then displays the 'title' field of each array entry in a table. Just the bare bones of the for loop is needed.

 

I can do mysql and tables.

Just not sure about arrays and doing multiple searches of mysql and displaying results.

_______________________________________________________________________________

 

So basically the number i the array is an ID in a mysql field called 'dependencies'.

I need to return the name of these dependencies from a mysql database and display them instead of the titles.

_______________________________________________________________________________

 

So Database =

ID:
56
21
67
Name:
Name1
Name2
Name3

 

Array =

$num[0]; //56

$num[1]; //21

$num[2]; //67

 

Display =

Name:
Name1
Name2
Name3

 

 

Thank you. :)

Probably:

<?php

$string = '12.56.79.35.93.22';

$num = explode('.', $string);

echo 'Number: ' . $string . '<br />
<h1>Names</h1>
';

$sql = 'SELECT `name` FROM `dependencies` WHERE `id` IN(' . implode(',', $num) . ')';
$qry = mysql_query($sql);

$i = 0;
while($row = mysql_fetch_assoc($qry))
{
    echo $num[$i] . ' - ' . $row['name'] . "<br />\n";

    $i++;
}

?>

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.