Jump to content

dont_be_hasty

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

dont_be_hasty's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks, Was able to use mysql_num_rows() to check if anything was being returned and if not it was displaying an error.
  2. Hi, So im creating a webpage using html, php and mysql. I have a form consisting of text boxes in which the user can enter values. So the user enters a value into the text box, and using php and mysql, the database display info relating this value. Example table: Table1(id, name, address, email, age). So say the user enters there name, it will display their address, email and age. But say the name doesnt exist in the database table, how do i display an message to say that it doesnt exist. Ive got it so that it will display a message if the text box is not filled in, but not sure how to go about displaying a message if the value does not exist. Thanks
  3. There is no error, just a blank space where it should be displaying them. It was displaying values before i added speciesdbname stuff to the equation and also returns values if i select 'All', so its seems to be something with the query and that its not successfully getting the speciesdbname
  4. Hi, Im using php and mysql as part of a web based project. The website has 3 seperate inputs, which the user can enter info, then using a mysql query it will display the correct infor from the database. Im using the following tables in the database. term(id, name, term_type, acc) gene_product(id, symbol, species_id) association(id, term_id, gene_product_id) gene_product_count(term_id, code, speciesdbname, species_id) So the user need to be able to input the following: symbol term_type speciesdbname The query will use all 3 of these and display the correct term names. I started with this query which uses just the inputed symbol. $query="SELECT name FROM term, association, gene_product WHERE association.term_id=term.id AND association.gene_product_id=gene_product.id AND symbol='$gene'"; I then changed it so it can use both gene name and term_type. if($ontology == "all") { $query1="SELECT name FROM term, association, gene_product WHERE association.term_id=term.id AND association.gene_product_id=gene_product.id AND symbol='$gene'"; } else { $query1="SELECT name FROM term, association, gene_product WHERE association.term_id=term.id AND association.gene_product_id=gene_product.id AND symbol='$gene' AND term_type='$ontology'"; } I now need to add the speciesdbname to the query, but im not sure how to go about it. Ive tried adding this: $query1="SELECT name FROM term, association, gene_product, gene_product_count WHERE association.term_id=term.id AND association.gene_product_id=gene_product.id AND gene_product.species_id=gene_product_count.species_id AND symbol='$gene1' AND term_type='$ontology' AND speciesdbname='$datasource'"; This doesnt seem to work. Ive also tried joining the gene_product_count and term table by term_id (as this both have this), but it didnt work either. Anyone got any ideas of what im doing wrong?
  5. Hi Im creating a guestbook using the following tutorial: http://www.phpeasystep.com/workshopview.php?id=15 Ive basically just copied that code and only changed things like username, database name etc... However when the user enters their details, it does not seem to actually add the details to the database. A new entry is added to the table but the info taken from the html does not seem to get added to the database correctly. Here is the code from the pages. Page with form: <table width="400" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC"> <tr> <form id="form1" name="form1" method="post" action="addguestbook.php"> <td> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> <tr> <td width="117">Name</td> <td width="14">:</td> <td width="357"><input name="name" type="text" id="name" size="40" /></td> </tr> <tr> <td>Email</td> <td>:</td> <td><input name="email" type="text" id="email" size="40" /></td> </tr> <tr> <td valign="top">Comment</td> <td valign="top">:</td> <td><textarea name="comment" cols="40" rows="3" id="comment"></textarea></td> </tr> <tr> <td> </td> <td> </td> <td> </td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" value="Submit"><input type="reset" value="Reset"></td> </tr> </table> </td> </form> </tr> </table> Code to add info to database: <?php $username="root"; // Mysql username $password=""; // Mysql password $database="assocdb"; // Database name $tbl_name="guestbook"; // Table name // Connect to server and select database. mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die("Unable to select database"); $datetime=date("y-m-d h:i:s"); //date time $query="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($query); //check if query successful if($result){ echo "<br>"; echo "<br>"; echo "Your comment was successfully added to the guestbook"; echo "<br>"; echo "<br>"; echo "<a href='viewguestbook.php'>View guestbook</a>"; // link to view guestbook page } else { echo "ERROR"; } mysql_close(); ?> </div> On this page the date/time is added correctly to the database, its just the info that is taken from the form that isnt added. There is a 3rd page that displays the info, but it shouldnt be that page that is causing the trouble. Thanks
  6. Thanks so much for the help. Thats gotten me a good bit further. However there is a problem with displaying the 3rd array: foreach ($set3 as $val) { print $val . '<br />'; } It gave me the following error: Warning: Invalid argument supplied for foreach(). I tired changing it round to use a while loop instead and it displayed nothing. Any ideas on what is wrong with the 3rd array? Thanks
  7. Hi, I have two mysql queries which save the results into arrays. I then need to use a for loop/loops (or a loop of some kind) to move through both these arrays. Basically i need to get the 1st result from 'array1' and run a mysql query using that result and the 1st result in 'array2', then still using the 1st result from 'array1' run the same query between it and 2nd result from 'array2' and so on till 'array2' runs out of results, then go back round the for loop and take the 2nd result from 'array1' and do the same with it. Im not very good with arrays and loops - theyre one of my reason for hating programming. Ill show you's what ive tried and failed at: Here is the code/queries i have been using to get my info from the database $query1="SELECT term_id FROM association, gene_product, term WHERE association.term_id=term.id AND association.gene_product_id=gene_product.id AND symbol='$gene1'";} $result1=mysql_query($query1) or die(mysql_error()); $row1 = mysql_fetch_array ($result1); $query2="SELECT term_id FROM association, gene_product, term WHERE association.term_id=term.id AND association.gene_product_id=gene_product.id AND symbol='$gene2'";} $result2=mysql_query($query2) or die(mysql_error()); $row2 = mysql_fetch_array ($result2); Here is the for loops i attempted: for ($i=1; $i<=$num1; $i++) { for ($i=1; $i<=$num2; $i++) { $query_d="SELECT distance FROM graph_path WHERE term1_id = '$row9[term1_id]' AND term2_id = '$row10[term2_id]'"; $result_d=mysql_query($query_d) or die(mysql_error()); $row_d = mysql_fetch_array($result_d); } } any one wondering - $num1 and $num2 is the number of results in the two arrays. When i tried to display the results in 'row_d' nothing was being displayed so ive obviously gone wrong somewhere. But hopefully you's can see what im trying to do. If anyone can help or even suggest another way of doing this it will be very much appreciated. Ive been struggling for ages now with this. Thanks
  8. Worked perfectly Thank you!
  9. Ok, so my webpage has 4 radio button they are: <input type="radio" name="id" value="???" checked> All <input type="radio" name="id" value="1"> 1 <input type="radio" name="id" value="2"> 2 <input type="radio" name="id" value="3"> 3 I then have a mysql query where i use the value selected from the radio box. But i need to know what value to i need put in the 'All' radio button (where the ? ? ? are) so that it can return results of any id (not just 1 or just 2, but can return 1, 2 and 3 altogether) Thanks
  10. mysql_num_rows($result1) - worked. Thanks.
  11. I basically have some code with queries my database and displays the results on a php webpage. I have the following tables in my database: term(id, term) product(id, product) join_table(term_id, product_id) Here is my code: $query1="SELECT term FROM term INNER JOIN join_table ON join_table.term_id=term.id INNER JOIN product ON join_table.product_id=product.id WHERE product = '$product1'"; $result1=mysql_query($query1) or die(mysql_error()); $row1 = mysql_fetch_array($result1); while($row1 = mysql_fetch_array($result1)) { echo $row1['term']; } This code display serveral terms on the screen. Is there any way in which i can save these into an array so that i can count how many terms are returned from the query. Thanks
  12. Yeah its a hard one to explain. I have the following tables: term(id, term) product(id, product) join_table(term_id, product_id) And the follwing code: $product1 = mysql_real_escape_string($_POST['product1']); $product2 = mysql_real_escape_string($_POST['product2']); $query1="SELECT * FROM term INNER JOIN join_table ON join_table.term_id=term.id INNER JOIN product ON join_table.product_id=product.id WHERE product = '$product1'"; $query2="SELECT * FROM term INNER JOIN join_table ON join_table.term_id=term.id INNER JOIN product ON join_table.product_id=product.id WHERE product = '$product2'"; $result1=mysql_query($query1) or die(mysql_error()); $result2=mysql_query($query2) or die(mysql_error()); $row1 = mysql_fetch_array($result1); $row2 = mysql_fetch_array($result2); while($row1 = mysql_fetch_array($result1)) { echo $row1['term']; } while($row2 = mysql_fetch_array($result2)) { echo $row2['term']; } The user inputs 2 products, the code basically get the id of this product then uses the join table to get the terms id/ids that match/link to this product id, then gets the terms that match the term id/ids. Whenever you display the results from row1 and row2, you usually get serveral terms being displayed (i think a product_id may have serveral term_ids). An example of this is: Row1 will display - term1, term2, term3, term4 Row2 will display - term2, term4, term6 In both of the rows term2 and term4 are display. How do i get it so that i only display the terms that match in each row (ie, only display term2 and term4). This is for a similarity project, so i need to display the similar results. If this cant be done is there away out counting how many terms displayed are the same. Like in the example above there is 2 similaritys, they are term2 and term4. So even if i can some how display the number of similar/match terms from each query/row would be great.
  13. Hi im working on a project using php and mysql and could do with some help. In the project the user enters two different id's and it displays the appropriate terms from the database, however i want to only displays terms that match from each id. Here is the code i have so far. $id1 = mysql_real_escape_string($_POST['id1']); $id2 = mysql_real_escape_string($_POST['id2']); $query1="SELECT term FROM table WHERE id = '$id1'"; $query2="SELECT term FROM table WHERE id = '$id2'"; $result1=mysql_query($query1) or die(mysql_error()); $result2=mysql_query($query2) or die(mysql_error()); $row1 = mysql_fetch_array($result1); $row2 = mysql_fetch_array($result2); echo $row1['term']; echo $row2['term']; When i display the results it displays the following Row 1: term1 term2 term3 term4 Row2: term2 term4 term6 term8 What i want to do is only display the terms that match is each row (Eg, i only want to display term2 and term4 as they are in both rows). Is there any way of doing this using php? Thanks
  14. If you set the hight to auto this might work. height:auto;
  15. Worked a treat. Thanks so much, i sat for ages trying to get that to work. I never was good with arrays, lol.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.