PHP - Php Multiplication Tables
Code: [Select]
<?php echo "<tableborder=1>"; echo "<table> \n"; echo " <tr>\n"; $a= 1; $b= 1; while ($a <= 9 && $b <= 10){ $calc = $a * $b; echo " <td>$calc</td>\n"; $a++; if ($a == 9){ echo " </tr>\n"; if ($b < 10) echo " </tr>\n"; $a = 1; $b++; } } echo "</table>"; ?> I am trying to do the multiplication tables but so far i can only manage to get this. it only shows the answers but i want it to show the tables along with the calculation, so for example: 1*2=2 2*2=4 etc. I want it to show on a repeating loop so it runs up to the 9 times tables. Any help on this? Similar TutorialsI am new to php and need help creating addition and multiplication tables using the html code we were given. I feel like I am on the right track, but I am getting a few errors and I cant figure them out. One of the errors is that it tells me I am not putting in a valid number for rows even though it is a positive number so it should work. Here is my code and all help is appreciated thanks in advance.
<html> <head/> <body> <form method="POST" action="<?= $_SERVER['PHP_SELF'] ?>"> <table border="1"> <tr><td>Number of Rows:</td><td><input type="text" name="rows" /></td></tr> <tr><td>Number of Columns:</td><td><select name="columns"> <option value="1">1</option> <option value="2">2</option> <option value="4">4</option> <option value="8">8</option> <option value="16">16</option> </select> </td></tr> <tr><td>Operation:</td><td><input type="radio" name="operation" value="multiplication" checked="yes">Multiplication</input><br/> <input type="radio" name="operation" value="addition">Addition</input> </td></tr> </tr><td colspan="2" align="center"><input type="submit" name="submit" value="Generate" /></td> </tr> </table> </form> <?php //check to see if num of rows is numberic if (isset($_POST["rows"]) && is_numeric($_POST["rows"])){ //check to see if rows is a positive number if($_POST["rows"] > 0){ if(isset($_POST) && $_POST['operation'] == "multiplication") { for($r = 0; $r < $_POST["rows"]; $r++){ echo '<tr>'; for($c = 0; $c < $_POST["columns"]; $c++){ echo '<td>' .$c*$r. '</td>'; echo '</tr>'; }} } else if (isset($_POST) && $_POST['operation'] == "addition") { for($r = 0; $r < $_POST["rows"]; $r++){ echo '<tr>'; for($c = 0; $c < $_POST["columns"]; $c++){ echo '<td>' .$c+$r. '</td>'; echo '</tr>'; } } } } else{ echo 'Invalid rows columns parameters'; exit(); } } else{ echo 'Invalid rows columns parameters'; exit(); } ?> </body> </html> I have a multiplication app that users will use as a test. The app has 9 multiplication problems that will be filled out. Then when the user hits the score button. It will then display the number of seconds it took to complete test and the answers that were filled out. What I want this app to do is display the ones that the user got wrong along with the correct answer. Not sure how I would do this. Here is my code to the app... Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Lab 5</title> </head> <body> <?php define ('ROWS', 3); define ('COLS', 3); define ('MAX_NUMBER', 12); date_default_timezone_set('America/New_York'); if (isset($_POST['btn_score'])) { //print_r ($_POST); $time1 = $_POST['ts']; $time1_object = new DateTime($time1); $now = new DateTime(); $time_span = $now->diff($time1_object); $minutes = $time_span->format('%i'); $seconds = $time_span->format('%s'); $seconds+= $minutes * 60; echo "It took $seconds seconds to complete the test<hr />"; foreach ($_POST as $problem => $answer) { if ($problem <> "btn_score" && $problem <> "ts") { //echo "$problem -- $answer <br />"; $problem = explode('_', $problem); $num1 = $problem[2]; $num2 = $problem[3]; echo "$num1 * $num2 === $answer <br />"; } } } ?> <h1>Lab 5</h1> <form name="lab5" method="post" action="lab5b.php"> <?php $now = new DateTime(); //echo $now->format('Y-m-d H:i:s'); echo "<input type='hidden' name='ts' value='" . $now->format('Y-m-d H:i:s') . "'>"; ?> <table border="1" cellspacing="5" cellpadding="5"> <?php $no_of_problems = 0; for ($row=0; $row<ROWS; $row++) { echo "<tr>"; for ($col=0; $col<COLS; $col++) { $num1 = mt_rand(1,MAX_NUMBER); $num2 = mt_rand(1,MAX_NUMBER); echo "<td>$num1 * $num2 </td>"; echo "<td><input type='text' size='2' name=${no_of_problems}_mult_${num1}_${num2}></td>"; $no_of_problems++; } echo "</tr>"; } $colspan = 2 * COLS; echo "<tr><td colspan=$colspan align='right'><input type='submit' value='Score' name='btn_score'></td></tr>"; ?> </table> </form> </body> </html> hi i need to get value after Multiplication in a loop as total, please how can i do that here is my code while ($row = mysql_fetch_array($name)) {?> <td><?php echo $row['service']; ?></td> <td><?php echo $result['qty'] ; ?></td> <td><?php echo $total = ($result['qty'] * $row['price']); ?></td> <?php } ?> i need to get $total of sum after loop, currently it shows only individual.. thanks for any help.. Regards Hi, I have the following script: <?PHP $match = '/.*?\\d+.*?(\\d+)(\\s+)/is' ; $dbh = new PDO('mysql:host=localhost;dbname=xxxx', 'xxxx', 'xxxx') ; $result = $dbh->query("SELECT companyName, invoiceAddress FROM detail_sheets WHERE area = 'Germany'") ; $codes = array() ; $names = array() ; $c0s = array() ; $c1s = array() ; $c2s = array() ; $c3s = array() ; $c4s = array() ; $c5s = array() ; $c6s = array() ; $c7s = array() ; $c8s = array() ; $c9s = array() ; while($row = $result->fetch(PDO::FETCH_ASSOC)) { if(preg_match($match, $row['invoiceAddress'], $matches)) { $codes[] = substr($matches[1], 0, 1) ; $names[] = $row['companyName'] ; //array_push($found, substr($matches[1], 0, 1), $row['companyName']) ; } } $i = 0 ; foreach($codes as $current) { $currentName = $names[$i] ; $result = $dbh->prepare("SELECT (sum(partbaskets.total) - sum(pourbaskets.total)) AS Margin FROM partbaskets, pourbaskets, enquiries, jobs WHERE partbaskets.enquiryRef = enquiries.id AND pourbaskets.enquiryRef = enquiries.id AND jobs.enquiryRef = enquiries.id AND jobs.status != 'Cancelled' AND enquiries.enqState != 'Inert' AND enquiries.companyName = ? ") ; $result->bindParam(1, $currentName, PDO::PARAM_STR) ; $result->execute() ; while($row = $result->fetch(PDO::FETCH_ASSOC)) { if($current == 0 && $row['Margin']) array_push($c0s, $row['Margin']) ; if($current == 1 && $row['Margin']) array_push($c1s, $row['Margin']) ; if($current == 2 && $row['Margin']) array_push($c2s, $row['Margin']) ; if($current == 3 && $row['Margin']) array_push($c3s, $row['Margin']) ; if($current == 4 && $row['Margin']) array_push($c4s, $row['Margin']) ; if($current == 5 && $row['Margin']) array_push($c5s, $row['Margin']) ; if($current == 6 && $row['Margin']) array_push($c6s, $row['Margin']) ; if($current == 7 && $row['Margin']) array_push($c7s, $row['Margin']) ; if($current == 8 && $row['Margin']) array_push($c8s, $row['Margin']) ; if($current == 9 && $row['Margin']) array_push($c9s, $row['Margin']) ; } $result = NULL ; $i++ ; } echo "<table><tr><td>Area</td><td>Margin</td></tr>" ; echo "<tr><td>Area 0</td><td>" . array_sum($c0s) . "</td></tr>" ; echo "<tr><td>Area 1</td><td>" . array_sum($c1s) . "</td></tr>" ; echo "<tr><td>Area 2</td><td>" . array_sum($c2s) . "</td></tr>" ; echo "<tr><td>Area 3</td><td>" . array_sum($c3s) . "</td></tr>" ; echo "<tr><td>Area 4</td><td>" . array_sum($c4s) . "</td></tr>" ; echo "<tr><td>Area 5</td><td>" . array_sum($c5s) . "</td></tr>" ; echo "<tr><td>Area 6</td><td>" . array_sum($c6s) . "</td></tr>" ; echo "<tr><td>Area 7</td><td>" . array_sum($c7s) . "</td></tr>" ; echo "<tr><td>Area 8</td><td>" . array_sum($c8s) . "</td></tr>" ; echo "<tr><td>Area 9</td><td>" . array_sum($c9s) . "</td></tr></table>" ; ?> But what is happening is that the Margin is being multiplied by the number of rows in partbaskets (which is the same amount of rows in pourbaskets). So for instance, if there is one part per job for a companyName, there is no problem and I get the correct margin. But, if there is say 4 parts for one of the jobs, then the margin for that job will be multiplied by 4, which is wrong. I have tried using GROUP but it didn't help. Can someone please give me the missing link in my SQL statement? Is it possible to put a multiplication problem in the mysql "default value" field? In my script I need to take the unit amount * quantity, I know how to do this in php, but can I just put my equation in the "default value" field in MYSQL and make it equal to another field?... Like excell? Thanks Im doing a search system and Im having some problems.
I need to search in two tables (news and pages), I already had sucess doing my search system for just one table, but for two tables its not easy to do.
I already use a select statment with two tables using UNION because I want to show number of search results, that is number of returned rows of my first sql statment.
But now I need to do a select statment that allows me to acess all fields of my news table and all fields of my pages table.
I need to acess in my news table this fields: id, title, content, link, date, nViews
I need to acess in my pages table this fields: id, title, content, link
Im trying to do this also with UNION, but in this case Im not having any row returning.
Do you see what I have wrong in my code?
<?php //first I get my $search keyword $search = $url[1]; $pdo = connecting(); //then I want to show number of returned rows for keyword searched $readALL = $pdo->prepare("SELECT title,content FROM news WHERE title LIKE ? OR content LIKE ? UNION SELECT title,content FROM pages WHERE title LIKE ? OR content like ?"); $readALL->bindValue(1,"%$search%", PDO::PARAM_STR); $readALL->bindValue(2,"%$search%", PDO::PARAM_STR); $readALL->bindValue(3,"%$search%", PDO::PARAM_STR); $readALL->bindValue(4,"%$search%", PDO::PARAM_STR); $readALL->execute(); //I show number of returned rows echo '<p>Your search keyword returned <strong>'.$readALL->rowCount().'</strong> results!</p>'; //If dont return any rows I show a error message if($readALL->rowCount() <=0){ echo 'Sorry but we didnt found any result for your keyword search.'; } else{ //If return rows I want to show, if it is a page result I want to show title and link that I have in my page table //if it is a news result I want to show title and link that I have in my news table and also date of news echo '<ul class="searchlist">'; $readALL2 = $pdo->prepare("SELECT * FROM news WHERE status = ? AND title LIKE ? OR content LIKE ? LIMIT 0,4 UNION SELECT * FROM pages where title LIKE ? OR content LIKE ? LIMIT 0,4"); $readALL2->bindValue(1, '1'); $readALL2->bindValue(2, "%$search%", PDO::PARAM_STR); $readALL2->bindValue(3, "%$search%", PDO::PARAM_STR); $readALL2->bindValue(4, "%$search%", PDO::PARAM_STR); $readALL2->execute(); while ($result = $readALL2->fetch(PDO::FETCH_ASSOC)){ echo '<li>'; echo '<img src="'.BASE.'/uploads/news/'.$result['thumb'].'"/>'; echo '<a href="'.BASE.'/news/'.$result['id_news'].'">'.$result['title'].'</a>'; //if it is a news result I also want to show date on my list //echo '<span id="date">'.$result['date'].'</span>'; echo '</li>'; } echo ' </ul>'; //but how can I do my select statement to have access to my news table fields and my page table fields?? } ?> This portion is kind of stumping me. Basically, I have a two tables in this DB: users and users_access_level (Separated for DB normalization) users: id / username / password / realname / access_level users_access_level: access_level / access_name What I'm trying to do, is echo the data onto an HTML table that displays users.username in one table data and then uses the users.access_level to find users_access_level.access_name and echo into the following table data, I would prefer not to use multiple queries if possible or nested queries. Example row for users: 1234 / tmac / password / tmac / 99 Example row for users_access_level: 99 / Admin Using the examples above, I would want the output to appear as such: Username: Access Name: Tmac Admin I am not 100% sure where to start with this, but I pick up quickly, I just need a nudge in the right direction. The code I attempted to create just shows my lack of knowledge of joining tables, but I'll post it if you want to see that I did at least make an effort to code this myself. Thanks for reading! I am trying to write some data from multiple SQL tables to a page. In the first table is a list of places. I then have more tables that are named after the different places. For example, say my first place in the list is called Place1. I have a table named Place1 with data that corresponds to place1. The data contained in the table named Place1 is a list of things to do in this place. It has 21 columns and each one is something to do in the morning, afternoon, and at night for each day of the week in the place Place1. What I am trying to do is display a sort of weekly calendar as a table on a webpage that lists all of the places in one column and then lists seven days of the week as 7 more columns. Then in each data cell I would want to list the things to do in the morning, afternoon and at night for the certain day of the week and for the place. The problem is that I am creating a CMS to allow other users with no coding knowledge to update events for other places, so I have to display data that could have been altered. The only solution I know of is to do a while loop that gets all of the place names and while there are still place names, write the place names to the page and set a variable equal to the place name. Inside the while loop I would create another while loop that each time the first while loop is executed uses the variable set in the first while loop to know which table to reference and then make a call to that table pulling out the 21 columns and writing them to the page. Each time the outer while loop executes, it would (hopefully) write the place name, and then set the variable as the current place name so that the inner while loop uses the variable to write the rest of the information about that place. I don't know if that would even work and if it did, I know it cannot be the best way to do this. I am pretty stuck here and don't really have a good solution so if anyone proposes a solution that is radically different to anything I have done, I am open to everything. Thank you! This is more than a question than anything else: I am looking for a tutorial or something that will allow me to make tables with php and mysql for example what I need is: mysql data: table = links lid = 1 lname = Page 1 linkid = page.php lid = 2 lname = Page 2 linkid = page2.php etc and i am try to get it so if there is 2 pages then the table would do Page 1 Page 2 if 3 Page 1 Page 2 Page 3 so there are 2 lname(s)s per row and 1 in each column and it would keep building the table and rows as more lname(s) are added. Does anybody know where to find a tutorial on doing something like this. Thanks in advance Hi everyone... I have a thumbnail page that is putting out tables that are skewed and I am not able to use CSS properly because of that. Is there anyways I can change the PHP output? This is my code... I think the highlighted area is responsible for my tables? But it is mismatching the <tr> and <td> tags.... I really want it to show a structured table.. like <table> <tr> <td> </td> </tr> </table> // Thumbnail Listing else if( $cid && empty( $pid ) ) { $number_of_thumbs_in_row = 4; // If current page number, use it // if not, set one! if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } // Define the number of results per page $max_results = 400; // Figure out the limit for the query based // on the current page number. $from = (($page * $max_results) - $max_results); $result = mysql_query(" SELECT photo_id , photo_caption , photo_filename , photo_category FROM gallery_photos WHERE photo_category='".addslashes($cid)."' LIMIT $from, $max_results "); $nr = mysql_num_rows( $result ); if( empty( $nr ) ) { $result_final = "\t<tr><td>No Photos found</td></tr>\n"; } else { while( $row = mysql_fetch_array( $result ) ) { $result_array[]= "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' class='img'/></a>"; } $result = mysql_query( "SELECT category_name FROM gallery_category WHERE category_id='".addslashes($cid)."'" ); list($category_name) = mysql_fetch_array( $result ); mysql_free_result( $result ); $result_final = "<tr>\n\t<td> <span class='navlinks'><a href=viewgallery.php>Albums</a></span><font color=#ff0000> >> </font> <span class='navlinks'><a href=viewgallery.php?cid=$cid>$category_name</a></span><br><br/><br/><br/></td>\n</tr>\n"; foreach($result_array as $thumbnail_link) { if($counter == $number_of_thumbs_in_row) { $counter = 1; [b][size=24pt][size=18pt][b]$result_final .= "\n</tr>\n<tr>\n";[/b][/size][/size][/b] } else $counter++; [b][size=18pt] $result_final .= "\t<td>".$thumbnail_link."</td>\n";[/size][/b] } if($counter) { And my HTML output shows the tables like this... Code: [Select] <body> <table width='100%' border='0' align='center' style='width: 80%;'> <tr> <td> <span class='navlinks'><a href=viewgallery.php>Albums</a></span><font color=#ff0000> >> </font> <span class='navlinks'><a href=viewgallery.php?cid=1>Abstract</a></span><br><br/><br/><br/></td> </tr> <td><a href='viewgallery.php?cid=1&pid=240'><img src='photos/tb_240.jpg' border='0' alt='End Of Day' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=239'><img src='photos/tb_239.jpg' border='0' alt='A Photographer's Dream' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=238'><img src='photos/tb_238.jpg' border='0' alt='Heaven's View' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=237'><img src='photos/tb_237.jpg' border='0' alt='Colorful World ' class='img'/></a></td> </tr> <tr> <td><a href='viewgallery.php?cid=1&pid=241'><img src='photos/tb_241.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=242'><img src='photos/tb_242.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=243'><img src='photos/tb_243.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=244'><img src='photos/tb_244.jpg' border='0' alt='' class='img'/></a></td> </tr> <tr> <td><a href='viewgallery.php?cid=1&pid=245'><img src='photos/tb_245.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=246'><img src='photos/tb_246.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=247'><img src='photos/tb_247.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=248'><img src='photos/tb_248.jpg' border='0' alt='' class='img'/></a></td> </tr> <tr> <td><a href='viewgallery.php?cid=1&pid=249'><img src='photos/tb_249.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=250'><img src='photos/tb_250.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=251'><img src='photos/tb_251.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=252'><img src='photos/tb_252.jpg' border='0' alt='' class='img'/></a></td> </tr> <tr> <td><a href='viewgallery.php?cid=1&pid=253'><img src='photos/tb_253.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=254'><img src='photos/tb_254.jpg' border='0' alt='' class='img'/></a></td> <td><a href='viewgallery.php?cid=1&pid=255'><img src='photos/tb_255.jpg' border='0' alt='' class='img'/></a></td> </table> </body> hi everyone, Whats the best way to put my displayed php into my table? I already have gotten to the point where it is displayed, but it looks basic, so i want it to look like the table below it.... i just havent quite figured out how to "space" the data out so it looks better? Is it just a case of printing out what i want where in the table? or is it something more complex? http://www.removalspace.com/indextwo.php Hi everyone! I am trying to figure out how to put echoed php results from mySQL database into a table ready for styling to look how i want it too. So far i have got to the point where the results are echoed out but they are not in a good table layout. (under "latest removalspace user's) I want it more structured in my table. I have found out how to create the table but just not been able to work out how to fit the echo's in without snytax errors??? the "new" table that i want to use is near the end of the script. Code: [Select] <?php // Make a MySQL Connection mysql_connect("***", "***", "***") or die(mysql_error()); mysql_select_db("***") or die(mysql_error()); // Retrieve all the data from the "example" table $result = mysql_query("SELECT company_name, location, postcode, basicpackage_description, premiumuser_description, upload FROM Companies") or die(mysql_error()); // store the records into $row array and loop through while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { // Print out the contents of the entry echo "Name:\r".$row['company_name']; echo "\r\rLocation:\r".$row['location']; echo "\r\rPostcode:\r".$row['postcode']; echo "\r\nBasic Users:\r".$row['basicpackage_description']; echo "\r\nPremium Users:\r".$row['premiumuser_description']; echo "\r\nlogo:\r".$row['upload']; echo "<img src=\"http://www.removalspace.com/images/COMPANIES" . $row['upload'] . "\" alt=\"logo\" />"; echo "<table> <tr><th>Comppany Name</th><th>Location</th><th>Postcode</th><th>Basic Members</th><th>Upgraded Users</th><th>Company Logo</th></tr> <tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>"; } ?> I want to read records from the database and print out in this table and I need help with the code. Code: [Select] <?php mysql_connect(localhost,root,""); mysql_select_db(oodb) or die( "Unable to select database"); $query=" SELECT * FROM oocust"; $result=mysql_query($query); $num=mysql_numrows($result); ?> <HTML><HEAD> <script type="text/javascript"> var monthNames = [ "January","February","March","April","May","June","July", "August","September","October","November","December" ]; var today = new Date(); var mmyy = monthNames[today.getMonth()] + " / " + today.getFullYear(); </script> </HEAD><BODY bgcolor="#CCCC99" background="oldorchard.jpg"><b><center> <font size=+2><b> Old Orchard Invoice </font>Date: <script type="text/javascript">document.write(mmyy);</script></center> echo "<TABLE BORDER="0" CELLPADDING="5" CELLSPACING="5" background="oldorchard.jpg"> <TD> <TABLE BORDER="0" CELLPADDING="10" CELLSPACING="10" background="oldorchard.jpg"> <TD> <TABLE BORDER="0" CELLPADDING="1" CELLSPACING="1" background="oldorchard.jpg"> <TD> <input type=text size=25 value="Old Orchard Plumbing"><br> <input type=text size=25 value="2210 E. Hogan Hollow Road"><br> <input type=text size=25 value="Margate, Fl 33063"><br></TD> <TR> <td> <input type=text size=3 value="Bill To:"><br> <input type=text size=25 value="$bname"><br> <input type=text size=25 value="$bstreet:">><br> <input type=text size=25 value="$bcity"><br> <input type=text size=25 value="$contact"><br></TD> <tr> <td> <input type=text size=5 value="Ship To:"><br> <input type=text size=25 value="$sname:"><br> <input type=text size=25 value="$street"><br> <input type=text size=25 value="$scity"></td> </TR> </TABLE> </TD> <TD> <input type=text size=25 value="Invoice No: $invnum"><br> <input type=text size=25 value="Date: $mm/dd/yyyy"><br> <input type=text size=25 value="Terms: $terms"><br> <input type=text size=25 value="Due Date: $duedate"><br> <input type=text size=25 value="Order No: $ordernum"><br> <input type=text size=25 value="Territory:"><br> <input type=text size=25 value="Salesperson:"><br> </TD> </TABLE> </TD> <TD align=center><img src="dave pic.jpg" width=250 height=350></td> </TABLE> echo "</tr>"; <hr> echo "</table>";mysql_close(); ?> </b></BODY></HTML> i have some code which loops through a table, and displays the results. i have then added extra code so that it loops through another table, and prints out the reults, that are related to the first loop. so the page should look like menu submenu 1 submenu 2 submenu 3 menu 2 submenu 4 etc The problem is that the code only prints out the first row from the first loop and nothing else. <?php $list = "SELECT * FROM section_main"; $result = mysql_query($list) or die ("Query failed"); $numofrows = mysql_num_rows($result); echo "<table border='1' id='section_list'>"; echo "<tr><th>section_id</th><th>section_title</th></tr>"; for($j = 1; $j < $numofrows; $j++) { echo '<tr>'; $row = mysql_fetch_array($result); echo "<td>". $row['section_id'] . "</td><td>". $row['section_title'] . "</td>"; $query = "SELECT section_sub.section_sub_title, section_sub.section_title WHERE section_sub.section_title = " .$row['section_title']."ORDER BY section_sub_title"; $result2 = mysql_query($query) or die ("query failed2");//This part does not work $numofrows2 = mysql_num_rows($result2); for($i = 0; $i<$numofrows2; $i++){ $row2 = mysql_fetch_array($result2); echo '<tr>'.$row2['section_sub_title'].''; } } echo "</tr>"; echo '</table>'; ?> Any help on whats wrong would be great Hello all , I have a small issue in regards to allowing for my results to be placed horizontally across the page instead of vertically. I find the code i have posted works well when it comes to finding and displaying my information as requested (vertically) , but i am having trouble with finding a way to display the results horizontally. I know i need a way to identify each result?in order to echo it out in between <td> </td> , but i am still unsure , a point in the right direction would be good as i am struggling to find a way thankyou. $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url']; $img = $runrows['image']; $id = $runrows['id']; echo " <table width='100px'> <h4><a href='http://$url'><b>$title</b></a><br /> $desc<br> <font color='00CC00'>$url</font></h4> <tr><img src='data:image/png;base64,$img' /> $id "; Hello to everybody! I'm developing a beach guid web site, and I need all beach spot have a Country, Region, SubRegion and Spot And I want display this in a <ul> hierarchy. I Create 4 tables TABLE coutry idCoutry name TABLE region idRegion idCoutry name TABLE subregion idSubRegion idRegion name TABLE beach idBeach idSubRegion name I would like display this values like that - Country - Region -SubRegion -Beach -Beach -Beach -Beach -Beach -SubRegion -Beach -Beach -Beach -Beach -Beach - Country - Region -SubRegion -Beach -Beach -Beach -Beach -Beach -SubRegion -Beach -Beach -Beach -Beach -Beach etc. I can do this with multi query but if I have 4000 Beachs the script made many query's If some can help me! Thanks! Hello, I'm trying to get a join with 2 tables but cannot get it to work. It's a contentsystem with an ID for the author. Another table tells the name of the author. Now I want to join these things. This is what i've coded so far: <? $query = "SELECT rmnl_content.content_aid, COUNT(rmnl_content.content_id), rmnl_crew.crew_id, rmnl_crew.crew_name FROM rmnl_content, rmnl_crew" "where rmnl_content.content_aid = rmnl_crew.crew_id"; $result = mysql_query($query) or die(mysql_error()); // Print out result while($row = mysql_fetch_array($result)){ echo " <b>". $row['COUNT(rmnl_content.content_id)'] ."</b> posted messages by ". $row ['crew_rmnl.crew_name'] ."</td> ."; echo "<br />"; } ?> hi i created a page where users can reply to a post and i saved there reply in a table i called comment.when new visitors click on a topic they can see the topic and the people that comment on the topic..Now my problem is this when i click on any topic it display the comment on that topic whch is good but also display comments from other topics wchich is not supposed to be.i have tried joining the tables but i keep getting syntax errors.is joining the comment table to the topics table the solution?? if so can anyone give me the proper way of joining a table but if there is another way kindly tell me.Thanks Quote $con = mysql_connect("localhost","****","****"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("checkmyw_database", $con); mysql_query("INSERT INTO requests (username, password, email, weavecode, mobile, jobtitle, relationship, sexuality, venue, type) VALUES ('$me', '$pw', '$email','1999','$mobile','$job','$relationship','$sexuality','$venue','newuser')"); mysql_query("INSERT INTO members (username, password, email, weavecode, mobile, jobtitle, relationship, sexuality,) VALUES ('$me', '$pw', '$email','1999','$mobile','$job','$relationship','$sexuality',)"); mysql_close($con); any idea why this doesn't work? Hi guy's, i have 2 tables and in both i need to cheack some variable, and i don't know how! I tried with mysql_num_rows, but it need to have min one as value. i cheacked in first table and if the table dosn't have that in it, i need to try with other one, but i dont know how! i hope you understand what is the problem! |