Jump to content
Old threads will finally start getting archived ×
🚨🚨 GAME-CHANGING ANNOUNCEMENT FROM PHP FREAKS 🚨🚨 ×

variables and separators


Mistral 🤖

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++;
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.