i have 2 tables in my MySQL. "groups" and "subgroups". like this:
- groups:
id
name
- subgroups
id
name
group
what i want is to print on the page all the groups and it s subgroups. this way:
$conn = db_connect();
$r = $conn->query("SELECT * FROM groups g INNER JOIN subgroups sb ON g.id = sb.group ORDER BY g.id");
if(!$r) throw new Exception( problems with query... );
$context .= <table width="150" border="1"> ;
while($row = $r->fetch_assoc())
{
$context .= "<tr><td>$row[subname]</td></tr>";
}
$context .= </table> ;
this prints out only all subgroups. i simply can t figure out how to print out all the groups too. structure of the database is this:
- groups:
id | name
1 | Group one
2 | Group two
- subgroups: (all of these subs belong to groups 1 & 2)
id | name | group
1 | Subone | 1
2 | Subtwo | 1
3 | Subthree | 1
4 | and again | 2
5 | and more | 2
6 | and last | 2
so what i want to see on the page is simple all groups and subs
get as in echo the contents. with php.
well- figured that out w/o help of anyone here- is there a way to delete sql data from php?
<form action="add_address1.php" method="post">
<?php
$id=$_REQUEST[ id ];
$conn=mysql_connect("localhost"-"root"-"");
mysql_select_db("neelima"-$conn);
if(isset($_POST[ add ]))
{
$name=$_REQUEST[ name ];
$id=$_REQUEST[ hid_id ];
$age=$_REQUEST[ age ];
$place=$_REQUEST[ place ];
$graduation=$_REQUEST[ graduation ];
$percentage=$_REQUEST[ percentage ];
$result=mysql_query("SELECT * FROM `db_address` WHERE name= $name ");
$num_of_rows = mysql_num_rows($result);
if($num_of_rows==0)
{
echo "allow to insert";
}
else
{
echo "show alert message like already username exists";
}
$query="INSERT INTO `db_address`(name-age-place-graduation-percentage) VALUES( $name - $age - $place - $graduation - $percentage )";
mysql_query($query);
header("location:address1.php?id=$id");
}
?>
<table border="2" bgcolor="#FFFFCC" align="center">
<input type="text" name="hid_id" value="<? echo $id;?>">
<tr><td>name</td><td><input type="text" name="name" value="<? echo $name;?> "></td></tr>
<tr><td>age</td>
mkdir($pname); or mkdir(localhost- pname);? or neither lol.
im very stuck it wont copy a file even i know it has access to do so mysql and php connect to database and write to it fine.
any and all help with this would be great
mkdir(d:/xampp/htdocs/pname);?
mkdir(localhost/xampp/htdocs/pname);?
<html>
<body>
<form method="get" action="search.php">
search for: <input type="text" name="search">
<input type="submit" name="submit" value="search">
</form>
<?php
if ($submit) {
echo "searching for: <b>$search</b><br />";
mysql_connect("mysql"- "username"- "password");
mysql_select_db("myDatabase");
$query="select * from myTable where firstName like %$search% ";
$result=mysql_query($query);
while ($row = mysql_fetch_object($result)) {
echo "Found: $row->firstName --$row->lastName<br />";
}
}
?>
</body>
</html>
- got it from a book but does not work. Should i sue the publishing company??:-)
this is a search engine for my database.
guys thanks very much. I have just tested Edison s code and it works. There- however- is a problem: it prints all the rows- like:
Found: 1st firstName value --1st lastName valueFound: 2nd firstName value --12nd lastName value
all in one row.
it was supposed to print only when it finds a match.
requinx- could you be kind enough to tell me the code as a whole? i am a beginner :-))) thanks
ok error: the 12 above is 2nd. the code prints the whole database not just the match.
Hi Edison-
Thanks a lot man- i submitted the code below but didnt work. Seems like a case of bad luck. Let s sleep on it for a while and see what happens :-)
thanks a lot- you ve been great help anyway- thanks for time.
$submit = $_GET[ search ];
if ($submit) {
echo "searching for: <b>$search</b>";
mysql_connect("mysql"- "username"- "password");
mysql_select_db("myDatabase");
$result = mysql_query("select * from myTable where firstName like \"%$search%\"
order by firstName");
echo "Found:<br>";
while ($row = mysql_fetch_array($result)) {
echo $row[ firstName ] ;
echo "--";
echo $row[ lastName ];
echo "<br>";
}
No comments:
Post a Comment