PHP - Need Help With Loops And Tables
I will start off by saying , I am a NooB. i understand concepts , but have trouble with figuring out the proper way to code thing out. I am trying to use an HTML form that the user can input two numbers, and use those numbers to create a table to be echoed back.
echo "<form action='action.php' method='post' name='columns'> Enter number of columns and rows to be displayed:<br /> Columns:<input type='text' name='colnums' size=3 maxlength=6 />Rows :<input type='text' name='rownums' size=3 maxlength=6 /> <br /><input type='submit' value='submit' /></form>" ; This is my form. I have made a loop that will display but not in the fashion i would like it to. for ($createColumns=$_POST['colnums']; $createColumns<=10 ; $createColumns++) { echo "<td>" . $createColumns . "</td>" ; } I am looking to write a script that only needs the user input for the number of rows and columns to be displayed. I think I need a range function or possibly an array for the possible numbers that can be input, but I'm not sure. The loop I've made has a top limit and an increment that i don't think i need. If you have any ideas I would greatly appreciate it. Similar TutorialsThis 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! 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?? } ?> 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! Did PHP a few years ago and for the life of me i can't work out why this doesn't work: Code: [Select] for ( $counter2=1; $counter2 < 1000; $counter2++) { for ( $counter1=1; $counter1 < 1000; $counter1++) { echo "Fixed bug"; } } and yet this does Code: [Select] for ( $counter2=1; $counter2 < 100; $counter2++) { for ( $counter1=1; $counter1 < 100; $counter1++) { echo "Fixed bug"; } } I tested it because I have a rather large amount of data to retrieve from an XML file and i kept receiving errors Hi guys
I just wanted to make a short post and talk about an issue im having and maybe get some advice. I know that loops aren't that hard to grasp and I shouldn't be having this much trouble understanding them but im just not getting it. I dont really know how to explain it but loops (like looping through mysql in an update statement) is foren to me and i was wondering if anyone had any advice for maybe learning them or maybe something im just over looking or maybe some good tutorials. I really want to get them down and start using them in scripts i right but im getting so frustrated because i constantly hear how easy they are and im just not getting it. if i wasn't clear please let me know and ill try to explain more clearly thanks guys JL Hi All, and thanks for your help on my last problem now solved. What i am doing is building a job site and it needs info put in from job seekers regarding their qualifications. Some will have 2 some may have 10 and so on. I need to set up a system that I can put say 10 text boxes in a form that can then go in a MySQL. I only want the filled out boxes to go into the database and not the ones left blank. I have no idea as to where to start with but I think I need to loop through until it comes to the last filled out box but not enter the blank text boxes. i have no idea where to start on this one so if any one has thoughts on this it would be great. Thank you all for your help in the past. Hello everyone, I've already posted a question trying to resolve my problem, but I've changed my code so much, I figured it may be best just to post a new thread with a better explanation of what I'm trying to do. Anyway, here's what I've got: I have a database with 2 tables: products and reservations. I have 3 products for now, that can be reserved for any date. I'm trying to create a page that will display all of the available products for a specific date. The user selects the date they want to check, and then the code should check their selected date and compare it with the database to display everything that is available on that date. The database looks like this: Products Table: prodid prodname 01 item 1 02 item 2 03 item 3 Reservations Table: prodid resdate 01 02/22/2012 01 02/23/2012 03 02/22/2012 Here is the code that I have now: Code: [Select] <?php $resultres = mysql_query("SELECT `prodid` FROM reservations WHERE `resdate` = '$resdate'") or die (mysql_error()); while ($rowres = mysql_fetch_row($resultres)) { $resprodid = $rowres[0]; $resultavail = mysql_query("SELECT `prodid` FROM products WHERE `prodid` != '$resprodid'") or die (mysql_error()); while ($rowavail = mysql_fetch_row($resultavail)) { $prodid = $rowavail[0]; echo $prodid; echo $proname; } } ?> When I select 02/21/2012, I get no results, where I should get all three products as a result, because none of them are reserved on this date. When I select 02/22/2012, I get a result of these products, in this order: 02, 03, 01, 02. I should get a result of ONLY 02, because this is the only product that isn't reserved for this date. When I select 02/23/2012, I get a result of 02 and 03, which in this case would be the correct return, because 01 is the only one reserved for this date. Any idea what I'm doing wrong here and how to fix it? Any help is GREATLY appreciated! i have been given this task in in uni. i was wondering it some one would be so kind to help me with it. all i have so far is this <?php for($x=1; $x<=3; $x=$x+1) { print "$x <br>"; } if ($x== "A") { } ?> the task is below Generate a number between 1 & 3 If 1 then assign A, If 2 then assign B, If 3 then assign C Add to a wordstring (using string concatenation with .) We need 3 letters generated to give a 3 letter word For loop (3) Generate a number between 1 & 3 If 1 then assign A, If 2 then assign B, If 3 then assign C Add to a wordstring (string concatenation with .) End loop Print 3 letter word i am a student and trying to figure out why this is not working for me i am trying to pull from my .txt file and add the lines. $numOrders should be 20 and $numCopies should be 52. it keeps telling me --Warning: feof() expects parameter 1 to be resource, string given on line 25. i really am having big trouble trying to understand how to use the while loop for this. any help would be great. here is my html code <html> <head> <title>Software1</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <h1>SOFTWARE ORDERS: REPORT</h1> <form action = "software1Boles.php" method = "post" > <p><input type = "submit" value = "Display the Report" /></p> </form> </body> </html> my php code <?php $totalCopies = $_POST['totalCopies']; $totalOrders = $_POST['totalOrders']; $nextOrder = $_POST['nextOrder']; $totalCopies = 0; $totalOrders = 0; $orderFile = fopen("ordersBoles.txt", "r"); $nextOrder = fgets ($orderFile); while (!feof($nextOrder)) { list($totalCopies, $totalOrders) = explode (":", $nextOrder); if ($totalCopies >=1 and $totalCopies >=1) { $totalCopies = $totalCopies + $nextOrder; $totalOrder = $totalOrder + $nextOrder; } $nextOrder = fgets($orderFile);} fclose($orderFile); print ("<h1>SOFTWARE ORDERS: REPORT</h1>"); print ("<p>TOTAL COPIES ORDERED: $totalCopies</p>"); print ("<p>TOTAL ORDERS: $totalOrders</p>"); ?> </body> </html> and my .txt file 1 Linux:1 2 Macintosh:1 3 Windows:1 4 Macintosh:1 5 Macintosh:2 6 Linux:5 7 Macintosh:10 8 Windows:10 9 Macintosh:1 10 Windows:1 11 Windows:1 12 Linux:1 13 Macintosh:5 14 Linux:4 15 Windows:1 16 Macintosh:1 17 Windows:1 18 Linux:2 19 Macintosh:2 20 Windows:1 21 anything you can give me would help alot, thanks i am having issues with my class work. this needs to start at the $startNum and end with the $endNum and display results in the increments submitted by the html. I can not get it to print out correctly it is supposed to say: The square of $startNum is $square //until it hits the end number and is going up by the correct increments, It wont go up by any increments and only shows a list if i leave out the increment-----any suggestions??? please i have to keep it very simple since i am just learning-ty html </head> <body> <h1>Squares</h1> <p> <form action = "squares2Boles.php" method = "post" > <p>Start with: <input type = "text" size = "5" name = "startNum" /> </p><p>End with: <input type = "text" size = "5" name = "endNum" /> </p><p>Increment by: <input type = "text" size = "5" name = "increment" /> </p><p><input type = "submit" value = "Display the Squares" /></p> </form> </body> </html> my php: <html> <head> <title>Squares</title> <link rel ="stylesheet" type="text/css" href="sample.css" /> </head> <body> <?php $startNum = $_POST['startNum']; $endNum = $_POST['endNum']; $increment = $_POST['increment']; $square = $_POST['square']; print ("<h1>SQUARES</h1><hr />"); for ($startNum = $startNum; $startNum <= $endNum; $startNum = $startNum + $increment) { $square = $startNum * $startNum; print ("The square of $startNum is $square<br />"); } print ("<hr />"); ?> </body> </html> I do not have the option that I know of to do a LIMIT 10 in my odbc query. How can I get it to count the number of while loops and stop at 10? Code: [Select] while (odbc_fetch_row($rs)) { } Man this is really driving me nuts. I can see my array values with echo inside the loop but outside nothing is shown. What am I missing here? If anything it should show the last value in the loop. while ($x = mysql_fetch_array($query_name,MYSQL_NUM)) { echo $x[0]; } echo $x[0]; hey guys, in my script i displays status' the users have posted. However when the users status' got over like 20, i noticed it was affected load times greatly as lots of SQL is looping. Code: [Select] <?php $sql = sqlcount(mysql_query("SELECT * FROM statuses LEFT JOIN users ON statuses.userid = users.id ORDER BY statusid DESC")); while ($row = mysql_fetch_assoc($sql)) { $status_id = htmlspecialchars($row['statusid']); $status = htmlspecialchars($row['status']); $time_posted = htmlspecialchars($row['time_posted']); $status_userid = htmlspecialchars($row['userid']); $sql2 = sqlcount(mysql_query("SELECT username,avatar_url FROM users WHERE id=$status_userid LIMIT 1")); while ($row2=mysql_fetch_array($sql2)){ $usernamestatus = $row2['username']; $avatar_url = $row2['avatar_url']; if (empty($avatar_url)) { $avatar = "<img src='$directory_self/images/default_avatar.gif' height='50px' width='50px' />"; }else{ $avatar = "<img src='$directory_self/photos/$usernamestatus/$avatar_url' height='50px' width='50px' />"; } echo '<div id="content">'; echo "<br />"; echo $avatar; echo "<a href=\"profile.php?id=$status_userid\">". $usernamestatus ."</a>"; echo "<br />"; $status = str_replace(array_keys($bbcode), array_values($bbcode), $status); echo $status; if($userid == $status_userid){ echo " <span class=x><a href=delete_status.php?id=$status_id>x</a></span>"; } echo "<br />"; echo format_date($time_posted); echo "<br />"; echo "<br />"; ?> <div id="like<?php echo"$status_id"; ?>"><a href="#" style="text-decoration: none" class="like" id="<?php echo"$status_id"; ?>"><span class="like_b"> <?php echo LANG_LIKE; ?> </span></a></div> <div id="unlike<?php echo"$status_id"; ?>" style="display:none"><span class="youlike_b"> <?php echo"$user"; echo LANG_LIKES_THIS; ?> </span><a href="#" class="unlike" id="<?php echo"$status_id"; ?>"><span class="unlike_b"> <?php echo LANG_UNLIKE; ?> </span></a></div> <?php echo "</div>"; } } ?> Is there a way to shorten this code and make it run faster, without as many queries? Cheers Hello, I am new in php and have made only little so fare. I am trying to make a script, but the script stops. I dont know how loops work. Quote <?php $lenkzeit = 4.5; $lenkunter = 1; $ruhezeit1 = 11; $ruhezeit2 = 9; $stunden1 = 0; $km = 1000; $kmh = 80; $stunden0 = $km/$kmh; $stunden01 = $stunden0; while ($stunden01 > $lenkzeit){ $stunden1 = $stunden1 + $lenkzeit + 1; $stunden01 = $stunden01 - $lenkzeit; //Stops here if ($stunden01 > $lenkzeit) { $stunden1 = $stunden1 + $lenkzeit + $ruhezeit; $stunden01 = $stunden01 - $lenkzeit; } } if ($stunden01 < $lenkzeit) { $srunden1 = $stunden1 + $stunden01; $stunden01 = 0; } echo $srunden1; ?> My goal here is to have it foreach group from the DB it'll create a new frameset with the groupName as the legend and then under each of those it will create another foreach for each of the fields inside of that group that has a enabled value of 0 from the db. Both queries work correctly. I just get trouble writing foreach loops and I'm not sure how this one is going to work out. Code: [Select] <?php session_start(); // Access the existing session // Include the database page require ('../../inc/dbconfig.php'); $defaultCharID = $_SESSION['defaultCharID']; $styleIDQuery = " SELECT characters.styleID FROM characters WHERE characters.ID = '" . $defaultCharID . "'"; $styleIDResult = mysqli_query ( $dbc, $styleIDQuery ); // Run The Query $row = mysqli_fetch_array( $styleIDResult, MYSQL_ASSOC ); $styleID = $row[ 'styleID' ]; $biofieldsQuery = " SELECT fields.*, groups.* FROM fields INNER JOIN groups ON fields.groupID = groups.ID WHERE groups.styleID = '" . $styleID . "' AND fields.styleID = '" . $styleID . "' AND groups.enabled = 0 AND fields.enabled = 0"; $biofieldsResult = mysqli_query ( $dbc, $biofieldsQuery ); // Run The Query $row = mysqli_fetch_array( $biofieldsResult, MYSQL_ASSOC ); $groupName = $row[ 'groupName' ]; ?> <script type="text/javascript"> $(document).ready(function() { }); </script> <!-- Title --> <div id="title" class="b2"> <h2>Character Management</h2> <!-- TitleActions --> <div id="titleActions"> <!-- ListSearch --> <div class="listSearch actionBlock"> <div class="search"> <label for="search">Recherche</label> <input type="text" name="search" id="search" class="text" /> </div> <div class="submit"> <button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button> </div> </div> <!-- /ListSearch --> </div> <!-- /TitleActions --> </div> <!-- Title --> <!-- Inner Content --> <div id="innerContent"> <form action="#" id="bioForm" > <fieldset> <legend><?php echo $groupName; ?></legend> <div class="field required"> <label for="matchType">Match Type Name</label> <input type="text" class="text" name="matchType" id="matchType" title="Match Type Name"/> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <input type="submit" class="submit" name="submitMatchType" id="submitMatchType" title="Submit Match Type" value="Submit Match Type"/> </fieldset> </form> </div> <!-- /Inner Content --> Hi all, I am desperately in need of some help here. I have been troubleshooting these codes for days, and I have posted this similar question quite a couple of times, and there is no answer from anyone... I am really in a bad shape now. Could someone please enlighten me to my problem? I have created 2 while loops...apparently the 2nd while loop overwrites the 1st while loop record. Meaning to say...1st while loop generates values of 'Math' 'Eng' 'Chi' 'Sci' AND store it in $subject_data, createLevelCheckboxes($subject_data, $level_data, 5); Apparently, the 2nd while loop takes only the last record 'Sci' from $subject_data and continues the looping. Which gives me results like Level 1 Sci Level2 Sci Level3 Sci I would like to attain something like.... Level 1 Math Level2 Eng Level3 Chi Level4 Sci Is there any reset which I need to do? while($data = mysqli_fetch_array($sql)) { if($current_level_id != $data['level_id']) { $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $current_level_id = $data['level_id']; $subject_data = array(); } //Add the current record to the $level_data array $subject_data[] = $data; } while($data1 = mysqli_fetch_array($sql1)) //Iterate throug the DB results { $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); $level_data = array(); $level_data[] = $data1; } $checkboxes .= createLevelCheckboxes($subject_data, $level_data, 5); Hi, I'm trying to create a script that imports a CSV file but gives the user 3 options: 1. If Exists Update 2. If Exists Keep Both 3. If Exists Ignore New The keep both is easy, I just insert everything without checks. However, the other 2 are a little bit tricky (in my mind anyway). I've been told I could create loops and that there isn't any easy way to do this with MySQL. I cannot use ON DUPLICATE KEY because the column that I'm checking cannot be unique (because I have the keep both option). Is it efficient in PHP to create a loop that checks each row to see if it exists? I'm a little hesitant because the files could be big and I'm not sure how efficient PHP is with CPU and memory resources. The App I'm making is designed to run in a business environment but it may run on servers that are handling more than one thing (not just web services). If anyone could give me a few pointers I'd be most grateful. Thanks. Hi @ all, I'm building a simpel agenda function for my boss Now I've ran in some basic query problems. First the code: <? include_once('../../config/config.php'); $query = "SELECT id, bedrijfsnaam, bezoeken FROM clients WHERE actief = 'ja' AND bezoeken > 0 ORDER BY id ASC"; $result = mysql_query($query)or die ("Query kon niet worden uitgevoerd"); echo '<table style="border-collapse:collapse;">'; while($row = mysql_fetch_assoc($result)){ extract($row); $bedrijfsnaam = ucfirst($bedrijfsnaam); $bedrijfsnaam = htmlentities($bedrijfsnaam); if($rowcount % 2 == 0) { echo '<tr onMouseover="this.style.backgroundColor=\'#649fbe\'"; onMouseout="this.style.backgroundColor=\'#fff\';" style="background-color:#fff; border-bottom: 1px solid black;">'; } else { echo '<tr onMouseover="this.style.backgroundColor=\'#649fbe\'"; onMouseout="this.style.backgroundColor=\'#f2f2f1\';" style="background-color: #f2f2f1; border-bottom: 1px solid black;">'; } $rowcount ++; // huidige jaar ophalen $huidig_jaar = date("Y"); echo' <td style="width: 313px; font-family: verdana; font-size: 10px; font-weight: bold; min-height: 20px;">'.$bedrijfsnaam.'</td> <td style="width: 8px; font-family: verdana; font-size: 10px; font-weight: bold;">'.$bezoeken.'</td> <td style="width: 100px; text-align: center; border-left: 1px solid black;">'; //januari ophalen $query1 = "SELECT datum FROM planning WHERE id = '.$id.' AND YEAR(datum) = '$huidig_jaar' AND MONTH(datum) = '01' ORDER BY id ASC"; $result1 = mysql_query($query1)or die ("Query 1 kon niet worden uitgevoerd"); $num1 = mysql_num_rows($result1); echo $num1; echo' </td> <td style="width: 100px; text-align: center; border-left: 1px solid black;">'; //februari ophalen $query2 = "SELECT datum FROM planning WHERE id = '.$id.' AND YEAR(datum) = '$huidig_jaar' AND MONTH(datum) = '02' ORDER BY id ASC"; $result2 = mysql_query($query2)or die ("Query 1 kon niet worden uitgevoerd"); $num2 = mysql_num_rows($result2); echo $num2; echo' </td> <td style="width: 100px; text-align: center; border-left: 1px solid black;">'; //februari ophalen $query3 = "SELECT datum FROM planning WHERE id = '.$id.' AND YEAR(datum) = '$huidig_jaar' AND MONTH(datum) = '03' ORDER BY id ASC"; $result3 = mysql_query($query3)or die ("Query 1 kon niet worden uitgevoerd"); $num3 = mysql_num_rows($result3); echo $num3; echo' </td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> <td style="width: 100px; text-align: center; border-left: 1px solid black;"></td> </tr> '; } echo '</table>'; ?> In the first query I'll get the id from all the clients in the database, now I want to use that id's in the upcoming query's (WHERE id = '.$id.'), but it allways uses the first id and not all the id's. $num always has the same result. Can anyone put me in the right direction? Thank you Sorry for my bad English, I'm dutch, can't help it I blame my parents... I hope it's enought information.... Greetings XistenceNL I created the code below and it outputs the following number output: 1111111773526604115551144611337112281111221111345 6789101121111100352004110051100611007110081100221 1003456789101141111100352004110051100611007110081 1002211003456789101151111100352004110051100611007 1100811002211003456789101123111110035200411005110 06110071100811002211003456789101134 Anyways if you look at the code, I need to be able to add the values on a single colony, idcol, with the same type and subtype, btid/stid, generated as the $prod variable. buildings with the same subtype generate the same resource, in this case, several iron mines and a single copper mine are present, but there are also 9 other types of resource buildings. How do I collect on the prods which go together? Code: [Select] <?php $dbhost = 'localhost:3306'; $dbuser = 'lordofth_aos'; $dbpass = 'flarge'; $dbname = 'lordofth_aos'; $conn = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Error connecting to mysql'); mysql_select_db($dbname); $query="SELECT id FROM users"; $result=mysql_query($query); $num=mysql_num_rows($result); $i=0; $idn=1; while($i<$num){ $queryii="SELECT idcol FROM colony WHERE id=$idn"; $resultii=mysql_query($queryii); $numt=mysql_num_rows($resultii); $id=mysql_result($result, $i); echo $id; $ii=0; $ibt=1; while($ii<$numt){ $querypty="SELECT btid FROM ptypes WHERE btid=$ibt"; $resultpty=mysql_query($querypty); $numpty=mysql_num_rows($resultpty); $idcol=mysql_result($resultii, $ii); echo $idcol; $bt=0; $btid=mysql_result($resultpty, $bt); echo $btid; $bte=1; while($bt<$numpty){ $querystid="SELECT stid FROM ptypes WHERE stid=$bte"; $resultstid=mysql_query($querystid); $numstid=mysql_num_rows($resultstid); $st=0; $stid=mysql_result($resultstid, $st); echo $stid; $ste=1; while($st<$numstid){ $bidum=0; $querybpid="SELECT bpid FROM blueprints WHERE btid=$btid AND stid=$stid"; $resultbpid=mysql_query($querybpid); $numbpid=mysql_num_rows($resultbpid); while($bidum<$numbpid){ $bidumb=0; $bidumbg=mysql_result($resultbpid, $bidum, 'bpid'); echo $bidumbg; $querybid="SELECT COUNT(bid) AS count, workers, efficiency FROM buildings INNER JOIN blueprints ON buildings.bpid=blueprints.bpid WHERE blueprints.btid=$btid AND blueprints.stid=$stid AND buildings.bpid=$bidumbg AND buildings.idcol=$idcol"; $resultbid=mysql_query($querybid); $staff=mysql_result($resultbid, $bidumb, 'workers'); $effic=mysql_result($resultbid, $bidumb, 'efficiency'); $count=mysql_result($resultbid, $bidumb, 'count'); echo $staff; echo $effic; echo $count; $prod=$staff*$effic*$count; echo $prod; $bidumb++; $bidum++; } $st++; $ste++; } $bt++; $bte++; } $ii++; } $i++; $idn++; } ?> I'm trying to send an email that has a list created from a while loop to multiple people with an email list created from while loop. Can someone please help me figure this out? My brain is fried. Here's the code that I have: This is producing an error message that reads: Parse error: syntax error, unexpected '{' in /home/content/29/6879529/html/calhoun/admin/sendreport.php on line 22 Code: [Select] <?php include("conf.inc.php"); $result = mysql_query("SELECT `prefix`,`lname`,`email` FROM admin"); $row = mysql_fetch_row($result); $result2 = mysql_query("SELECT `to`,`from`,`subject`,`message`,`date` FROM allmsgs WHERE reported = 'n' ORDER BY `messid` ASC"); $row2 = mysql_fetch_row($result2); $cdate = date('m-d-Y'); while ($row = mysql_fetch_row($result)) { $prefix = $row[0]; $lname = $row[1]; $adminemail = $row[2]; $fullname = "$prefix $lname"; $sendto = "$adminemail"; $emailsubject = "Webstats Report For $cdate."; while ($row2 = mysql_fetch_row($result2){ // This is line 22. $to = $row2[0]; $from = $row[1]; $subject = $row[2]; $message = $row[3]; $datetime = $row[4]; $eachmessage = "<p> <hr width=\"400\"> To: $to<br> From: $from<br> On $datetime<br> <br> $subject<br>$nbsp;<br> $message </p>"; } $emailmessage = "<html> <body> $fullname, <p> Here is a list of the messages that have been exchanged in the last 24 hours.</p> $eachmessage </body> </html>"; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'From: Webstats <reports@webstats.com>' . "\r\n"; // Mail it mail($sendto, $emailsubject, $emailmessage, $headers); } ?> |