FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » parameters with numbers
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: parameters with numbers [message #178855 is a reply to message #178853] Tue, 14 August 2012 22:15 Go to previous messageGo to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma:
Senior Member
On Tue, 14 Aug 2012 22:16:55 +0200, houghi wrote:

> I have something like the following:
>
> <?php include_once('connect.php');
> $ncast_1 = 'nm0001147';
> $ncast_2 = 'nm0518718';
> $ncast_3 = 'nm0001212';
> $ncast_4 = 'nm0004825';

You could declare these as an array:

$ncast = array('nm0001147','nm0518718','nm0001212','nm0004825');

> for ($i = 1; $i <= 4; $i++) {

In an array, your indexes start from 0 by default:

for ($i = 0; $i < 4; $i++) { // this gives 0, 1, 2, 3

> $sql = "SELECT * FROM cast WHERE nconst LIKE '$ncast_1'";

Then in this line, you could use:

$sql = "SELECT * FROM cast WHERE nconst LIKE '{$ncast[$i]}'";

Note that the {} are essential when you want to reference an array inside
a php string, which in this case is everything between the " characters!

> $result = mysql_query($sql) or die(mysql_error());
> $row = mysql_fetch_array( $result );
> $cast_[$i] = $row['name'];
> echo "$cast_[$i] $i <br>";
> }
> mysql_close($conn);
> ?>
>
> This works as expected, but not as I want it to work. The $ncast_1 after
> the LIKE in the $sql should vary with the value of $i.

Rgds

Denis McMahon
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: PHP Debugger which can set breakpoint and view variables on watch window
Next Topic: PHPUnit documentation
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 11:35:49 GMT 2024

Total time taken to generate the page: 0.04994 seconds