PDA

View Full Version : Can i use Select to query mulitple data from within a field of a table?


swatisonee
08-27-2005, 07:54 AM
I would be grateful if someone could tell me whether Select is appropriate to choose data within a field and separated by commas . I have made the foll. script. What I want to achieve, is below the script. Any and all advise would be welcome. Thank You.


<?php
mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");

mysql_select_db($database)
or die ("Unable to select database.");

$result2 = mysql_query("SELECT * FROM `Makers` WHERE `Makerid`='$b' ");
$myrow3= mysql_fetch_array($result2);
$Name=$myrow3["Name"];

$result = mysql_query("SELECT * FROM `Market` WHERE `Equipment` = '$Name' ");

if ($myrow = mysql_fetch_array($result)) {

do {
printf(

$myrow["ID"],
$myrow["Kiddo"],
calculatedate($myrow["Date"]),
$myrow["Equipment"]);

} while ($myrow = mysql_fetch_array($result));


} else {

echo "Sorry, no records were found!";
}


?>


My table currently has the foll. info.



Kiddo Equipment
abc bells, whistles
def bells, tops, shovels
ghi shovels
jkl tops, whistles

So when Mr Bell Maker wants to see which kids are using his bells, he should be able to see:

Kiddo

abc
def

Similarly, Ms. Shovel Maker should be able to see:
Kiddo

def
ghi

Kid Charming
08-28-2005, 01:28 AM
SELECT
kiddo
FROM
table
WHERE
equipment LIKE '%bell%'


But storing multiple values in one field is poor database design, and it'll eventually break your heart. Google 'database normalization.'

swatisonee
08-28-2005, 09:42 AM
The story of my life ! I inheirted a db of over 60 tables from another person and now i have to build upon it...

I WAS ABLE TO solve it using


mysql_connect("localhost", $dbname, $dbpasswd )
or die ("Unable to connect to server.");

mysql_select_db($database)
or die ("Unable to select database.");

$result = mysql_query("SELECT * FROM `Market` WHERE ( (`Equipment`

LIKE '%$a%')OR (`Equipment` LIKE '%$Name%')) ");

if ($myrow = mysql_fetch_array($result))
{
do
{
printf("
",
$myrow["Equipment"],
$myrow["Kiddo"]);

}


while ($myrow = mysql_fetch_array($result));
}

else
{
echo "Sorry, no records were found!";
}

Thanks anyway for looking at it !