Thanks for the responses Michael and Bob! Yeah, I'm super noob to all this ^.^
I changed the column to "id" from "index" that seems to have fixed the problem..
kinda... now when I have it print values from the columns in that row, it all seems to
be empty. When I tell it to just print the array it simply prints "Resource id #3"
I'm not really sure what that means... Here's my code...
<?php
$dbh=mysql_connect ("localhost", "kipples_women", "xxxx") or die ('I cannot connect to
the database because: ' . mysql_error());
mysql_select_db ("kipples_hotwomen");
$query="SELECT * FROM women WHERE 'id=$id'";
$result=mysql_query($query) or die("Query failed : " . mysql_error());
$array=mysql_fetch_array($result);
$getdate = getdate();
if ($array['year'] == 0)
$age = 0;
else
$age = $getdate['year'] - $array['year'];
if ($array['ydays'] > $getdate['yday'])
$age = $age - 1;
?>
<div class="womendetailed">
<center><h2><?= $array['first'].' '.$array['last'] ?></h2></center>
<h3>She was born in <?= $array['year'].' and is '.$age.' years old' ?></h3>
<h3><?= $array['desc']?></h3>
<?php
mysql_free_result($result);
mysql_close($dbh);
?>
Also, in the last email, when I said LIMIT $id Oo.. the Oo was supposed to be oooo and
went with the and ^.^ so "oooo, and blah blah blah" :) sorry for any confusion. Very
good to know what LIMIT does, i was thinking if you said for example, LIMIT 3, 8 it
would only get results from index value 3-8 so I figured if I said LIMIT $id it would
only get that row :) thanks for clearing that up!
Kip Gordon
----- Original Message -----
From: Michael Stassen
To: Kip Gordon
Cc: [EMAIL PROTECTED]
Sent: Saturday, May 08, 2004 10:05 PM
Subject: Re: Another Stupid Newbie Question ^.^
Kip Gordon wrote:
> I connect to my data base...
>
> $dbh=mysql_connect ("localhost", "kipples_women", "xxxx") or die ('I cannot
connect to the database because: ' . mysql_error());
> mysql_select_db ("kipples_hotwomen");
>
> and then I issue a query..
>
> $query="SELECT *
> FROM women
> WHERE index = $id";
> $result=mysql_query($query) or die("Query failed : " . mysql_error());
>
> now here's where it gets funky, and where I can't figure out what is going wrong...
> I now have it display the information from the row that has the field
> "index" and where index is equal to $id (the number from the url). Now, say
> that $id was equal to 21... I get an error message that says..
>> " Query failed : You have an error in your SQL syntax. Check the manual
> that corresponds to your MySQL server version for the right syntax to use
> near 'index = 21' at line 3"
> Now, first of all, it isnt on line3, its like line 128 or something...
The error message is coming from mysql with regard to your 3-line query.
The mysql server has no way of knowing which line of your script sent the query.
The problem is that index is a reserved word. Your best bet would be to use
a different name for the column, id perhaps. If you wish to use a column
named index, you must enclose it in backticks, like this:
$query="SELECT *
FROM women
WHERE `index` = $id";
But I'd recommend
ALTER TABLE women CHANGE `index` id INT;
to rename the index column to id. (Replace "INT" with the same column type
you used to define index.) Then your query becomes
$query="SELECT *
FROM women
WHERE id = $id";
No more need for backticks, and "WHERE id = $id" is intuitive.
> second.. I can't see anything wrong with that syntax... My SQL server
> version is 4.0.18-standard and I can't find documentation for it. I also
See the online manual <http://dev.mysql.com/doc/mysql/en/>.
> tried to use LIMIT $id Oo and it gets even weirder. I can get a result with
> LIMIT $id.... but it pulls the wrong row! if $id equals 24 for example, it
> will get the row with a value of 7 in the field for index.... I don't get
> it.. Even had a friend look at it and he said it all looked good..
I'm not sure what you mean by "LIMIT $id Oo", but no, it doesn't pull the
wrong row. LIMIT has nothing to do with which rows are selected. That's
the job of the WHERE clause. Nor does it have anything to do with how the
returned rows are sorted. That's the job of the ORDER BY clause. LIMIT is
used to determine how many rows are returned if you don't want them all.
Thus, LIMIT 24 means you want the first 24 rows that match your WHERE
clause. See the manual <http://dev.mysql.com/doc/mysql/en/SELECT.html> for
the complete SELECT syntax.
> I'd really appreciate any help anyone could throw at me... I'm rather new to all
this!
>
> Thanks,
> Kip Gordon
We were all new once. Hope this helps.
Michael
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]