# Selecting specific data from MySql using php, working with numbers not letters

**URL:** <https://forum.kirupa.com/t/selecting-specific-data-from-mysql-using-php-working-with-numbers-not-letters/184704>\
**Category:** Uncategorized\
**Created:** [April 6, 2006, 11:47pm UTC](https://forum.kirupa.com/t/selecting-specific-data-from-mysql-using-php-working-with-numbers-not-letters/184704 "2006-04-06T23:47:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![devinstar](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@devinstar](https://forum.kirupa.com/u/devinstar)\
**Post date:** [April 6, 2006, 11:47pm UTC](https://forum.kirupa.com/t/selecting-specific-data-from-mysql-using-php-working-with-numbers-not-letters/184704/1 "2006-04-06T23:47:25Z")

</div>

Hi,

The problem. I want to select all the data in my msql database which has a specific id. e.g. I have three primary ids ‘cell1’, ‘cell2’ and ‘cell3’ etc. okay so you get the idea.

Now I want to select all the data the has a primary id of say ‘cell2’ and spit it back.

I have got this working, but only when the primary key is a number and not when it is a combinantion of letters and numbers or just letters.

This is the php code I am using. The field in the mySql Database is of the varChar type so this shouldn’t be the problem, should it?

PHP CODE:

$phpvar1 = $\_GET[“scell”];

$query = “SELECT \* FROM tableName WHERE filePath = $phpvar1”;

$result = mysql\_query($query);

$num\_rows = mysql\_num\_rows($result);

while($row = mysql\_fetch\_array($result))  
{  
$filepath = $row[1];

```
     $data .= $filepath;
     $data .= "//";

```

}  
echo “info=$data”;

The error I get when the primary ID has any letters in it is

“ **Warning** : mysql\_num\_rows(): supplied argument is not a valid MySQL result resource in **/home/devinchcom/public\_html/flashupload/selectData.php** on line \*\*13”  
\*\*  
Any help would be great.

Thanks!

DC

---

<div class="post-metadata">

**Author:** ![bwh2](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@bwh2](https://forum.kirupa.com/u/bwh2)\
**Post date:** [April 7, 2006, 12:29am UTC](https://forum.kirupa.com/t/selecting-specific-data-from-mysql-using-php-working-with-numbers-not-letters/184704/2 "2006-04-07T00:29:33Z")

</div>

change to

```php

$query = "SELECT * FROM tableName WHERE filePath = '$phpvar1'";

```

---

<div class="post-metadata">

**Author:** ![devinstar](https://avatars.discourse-cdn.com/v4/letter/d/e495f1/32.png) [@devinstar](https://forum.kirupa.com/u/devinstar)\
**Post date:** [April 7, 2006, 12:33am UTC](https://forum.kirupa.com/t/selecting-specific-data-from-mysql-using-php-working-with-numbers-not-letters/184704/3 "2006-04-07T00:33:43Z")

</div>

Thanks bwh2, it works now 🙂

---

<div class="post-metadata">

**Author:** ![bwh2](https://avatars.discourse-cdn.com/v4/letter/b/8c91f0/32.png) [@bwh2](https://forum.kirupa.com/u/bwh2)\
**Post date:** [April 7, 2006, 1:06am UTC](https://forum.kirupa.com/t/selecting-specific-data-from-mysql-using-php-working-with-numbers-not-letters/184704/4 "2006-04-07T01:06:04Z")

</div>

no problem. you’re also creating a bunch of unnecessary variables in your code, so you could clean it up by getting rid of them. when i first started learning php, my code looked a lot like yours, but now i’ve learned to clean it up.

```php

$phpvar1 = $_GET["scell"];
$result = mysql_query( "SELECT * FROM tableName WHERE filePath = '$phpvar1'" )
$num_rows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
    $data .= $row[1].'//';
} 
echo 'info=$data';

```

btw, if you have any other code questions, you can use the [php] tags (take away the spaces before and after php).
