Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6784
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: parameters with numbers |
| Date | 2012-08-14 22:15 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <k0eimp$q25$2@dont-email.me> (permalink) |
| References | <slrnk2lchn.drm.houghi@penne.houghi> |
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
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
parameters with numbers houghi <houghi@houghi.org.invalid> - 2012-08-14 22:16 +0200
Re: parameters with numbers Christoph Becker <cmbecker69@gmx.de> - 2012-08-14 23:27 +0200
Re: parameters with numbers Denis McMahon <denismfmcmahon@gmail.com> - 2012-08-14 22:15 +0000
Re: parameters with numbers houghi <houghi@houghi.org.invalid> - 2012-08-15 00:31 +0200
csiph-web