PHP - Working With More Then Two Tables...help!!!
holla everybody
so back again with another crazy question am working on a small database with 3 to 4 tables. need at least 3 tables. the problem is that if i work with two of them, it works perfectly, as soon as i add the 3rd one, and try to edit a record, it edits only the 1st row and not all the rows required the first table is called "perso" containing the personal data of the employees the second table is called "center" this contains the information of the starting and ending dates of an employee on a center. the third table is called "dp" it contains the workplan of the employee all the 3 tables have a common fiield "pid" which is identical now i want the form to display alle the records suppose in the department IT, the workers have their plan of starting their work on a certian center on a certian date to a certian date. usually 2 weeks to a month. they should therefor appear on the plan of the specified center. it is simple if i am using the dp and center tables, but i want the perso table too so that i can display the names according to the pid. and maybe some other tables containing information of vacation etc. but as i said, as soon as i add the 3rd table to the query, it breaks down. please check the code: // the form code <? require "db_credentials.php"; // here is the problem, in the following query, if i add "from dp, perso, center where dp.pid = center pid it wont work. but as long as it looks like below, it works find... $result=mysql_query("select * from dp, perso where dp.pid = perso.pid order by dp.id asc"); // Fetch record rows in $result by while loop and put them into $row. while($row=mysql_fetch_assoc($result)){ ?> // then the table with cells filled with such code: <? echo $row['FirstName'] . " " . $row['LastName']; ?> <select name="monday_<? echo $row['id']; ?>" id="select3"> <option>Select</option> <option style="background-color:#FF0000 ">FDLS</option> <option style="background-color:#FF0000 ">FDFD</option> //and so on till sunday again <? } // End while loop. ?> ********************************************* <? if($_POST['Submit']){ // Connect database. $host="mysql"; $db_user="name"; $db_password="password"; $database="my_db"; mysql_connect($host,$db_user,$db_password); mysql_select_db($database); $result=mysql_query("select id from dp order by id asc"); while($row=mysql_fetch_assoc($result)){ $mo=$_POST["monday_".$row[id]]; mysql_query("update dp set Mo='$mo'' where id='$row[id]'"); } echo "--- DB Updated---"; } ?> ================================ all help will be very much appriciated thanks in advance Similar TutorialsI am entering a question and notes into one table and creating an ID number in Table 1: $qid (Question ID) $question $notes I am then entering an answer and creating an ID for the answer which sites next to question ID in Table 2: $aid (Answer ID) $answer I am now trying to transfer the Question ID into Table 2. I am currently trying to do this as a hidden string: <input name="category" type="hidden" value="$qid" id="qid" > Does any one have any advice on how I can use two fields. Can I display or insert data with the same php script? So I have 2 tables, a student table and a course table. When I add a new course to my course table it should be available to students to sign up for which goes into the student table when they do. However now I have to create a page which displays the different courses (course table) and when you click on a course it should display all the users registered for that specific course. Also when a course gets deleted all the student registered for that course should be deleted. So deleting a course in the course table should delete student in the student table.. I have already created a page which display the different course information and I am familiar with creating pages that allows you to delete table info from the page. However, I am lost on how to display the students when clicking on the course and how to link the 2 tables so when deleting a course it deletes the students aswell. Where should I begin with this and how should I go about it? This is my code up until now for displaying the different courses: Code: [Select] <?php $query=mysql_query("SELECT * FROM course "); while ($rows = mysql_fetch_array($query)): $cname=$rows['cname']; $cid=$rows['cid']; echo "<table> <tr> <td> $cname </td> <td> $cid </td> </tr> </table> "; endwhile; This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=342956.0 hi everybody simply love this forum because i always get the question perfectly answered. i am here this time with a rather complicated question: i am creating a simple duty plan for different departments for exeample department #1 is "Tech" and department #2 is "Service" different employees working in these departments change their dutys and will are sent to another department or section or go on holidays. this is why i have at least 4 different mysql tables to store the data:- personel(storing the personal information of the workers) dutyplan(storing the week's working daysy of the workers) departments(storing the starting and ending dates of the department change) vacation(stores the start and ending dates of the vacations) in all the tables the common id is the pid which is issued unique to every worker. i am still able to work only with the 1st two tables. i can edit and create new plans for the weeks for employees working in the departments with the following php code(submitting only to edit the plan) if i add a date range for example Monday the 24th of January to Sunday the 30th of January for an employee working in the Tech department to work a few days in service department, it will show the employee in the week on the plan of both departments. if both department heads edit the plan without communicating to each other, and knowing on which date the worker goes out and in to the department, the 1st one will plan him for the whole week on his dutyplan and the second department head will overwrite this plan(if edited) or if creating a new plan(create the duty of the worker also one more time). i want to avoid this confusion and manual work. the same is with the vacation or sickness tables, if the employee has vacation, the program should check and return the selected value in the pulldown menu with the value stored in the vacation or sickness tables appropriate to the date in the plan table. ************************************************************************ form.php: <? require "config.php"; $result=mysql_query("select * from personel, dutyplan, department, vacation WHERE personel.pid = dutyplan.pid and personel.pid = vacation.pid and dp.pid = departments.pid and departments.Section = 'Service' order by dp.id asc"); ?> <? while($row=mysql_fetch_assoc($result)){ ?> // after that i create table, displaying all the days of the week from monday to sunday and use this code <tr> <td><? echo $row['FirstName'] . " " . $row['LastName']; ?>: </td> <td> <select name="monday_<? echo $row['id']; ?>" id="select1"> <option><? echo $row['Mo']; ?></option> <option>Duty</option> <option>Free</option> <option>Vacation</option> //the same way down to sunday, for every day the different options to be selected. it displays the records perfectly, as long as there is no change of department planed and the vacation must also be selected manually. +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ update.php <? if($_POST['Submit']){ require "includes/config.php"; $result=mysql_query("select * from dutyplan, departments, vacation order by dutyplan.id asc"); while($row=mysql_fetch_assoc($result)){ $mo=$_POST["monday_".$row[id]]; $tu=$_POST["tuesday_".$row[id]]; $we=$_POST["wednesday_".$row[id]]; $th=$_POST["thursday_".$row[id]]; $fr=$_POST["friday_".$row[id]]; $sa=$_POST["saturday_".$row[id]]; $su=$_POST["sunday_".$row[id]]; mysql_query("update dp set Mo='$mo', Tu='$tu', We='$we', Th='$th', Fr='$fr', Sa='$sa', Su='$su' where id='$row[id]'"); } echo "Records updated"; } ?> **************************************************** how would you gueys solve this problem? many thanks in advance Hi guys, I'm trying to query two tables for different data and echo the results that match both tables. Here are the tables I have and the query I'm trying to run. (Table) qc_reports (Fields) id report_date report_lot_number report_po report_supplier report_buyer report_inspectedby report_pulptemprange report_carrierconditions report_supplierclaim report_carrierclaim report_temprecorder report_temprange_N report_temprange_M report_temprange_B report_suppliercontact report_contactedby report_time report_comments (Table) qc_lots (Fields) id report_id lot_temprange lot_commodity lot_rpcs lot_brand lot_terms lot_cases lot_orgn lot_estnum lot_avgnum This is the query that I'm trying to do. Code: [Select] <?php $sql = "SELECT * FROM qc_reports, qc_lots WHERE "; if (!empty($start_date) and !empty($end_date)) $sql .= " qc_reports.report_date BETWEEN '$start_date' and '$end_date' AND "; if (!empty($search_fronteralot)) $sql .= " qc_reports.report_lot_number = '$search_fronteralot' AND "; if (!empty($search_buyer)) $sql .= " qc_reports.report_buyer = '$search_buyer' AND "; if (!empty($search_supplier)) $sql .= " qc_reports.report_supplier = '$search_supplier' AND "; if (!empty($search_po)) $sql .= " qc_reports.report_po = '$search_po' AND "; if (!empty($search_carrierconditions) and $search_carrierconditions != 'all') $sql .= " qc_reports.report_carrierconditions = '$search_carrierconditions' AND "; if (!empty($search_commodity) and $search_commodity != 'all') $sql .= " qc_lots.lot_commodity = '$search_commodity' AND "; if (!empty($search_inspectedby)) $sql .= " qc_reports.report_inspectedby = '$search_inspectedby' AND "; $sql = substr($sql, 0, -4); $query = mysql_query($sql); $numrows = mysql_num_rows($query); ?> RESULTS - <?php echo $numrows; ?> <hr> <table width='500'><tr><td><b>Date</b></td><td><b>Lot Number</b></td><td><b>PO</b></td><td> </td></tr> <tr> <td> </td> </tr> <?php while ($row = mysql_fetch_assoc($query)) { $id = stripslashes($row['id']); $report_lot_number = stripslashes($row['report_lot_number']); $report_po = stripslashes($row['report_po']); $report_date = stripslashes($row['report_date']); echo "<tr> <td>" . $report_date . "</td></td><td>" . $report_lot_number . "</td><td>" . $report_po . "</td><td><a href='view_report.php?id=" . $id . "'>View</a></td> </tr>"; } echo '</table><br><br><br><hr><br><br>'; } ?> All the variables are passed from a HTML form with $_POST. I need the search to work like this: If there is a value in a form field then the query gets appended with that value but when it gets to the $search_commodity it needs to search the second table (qc_lots) and check for the results. Any results that match have to be matched to the results from the first table (qc_reports) and display (echo) only qc_reports that match to both tables. The only common field is the report_id on the qc_lots table and the id on the qc_reports table. I'm stuck and need some guidance. Can someone help please? Back with a new problem. I have 8 tables interconnected. Table#1 - Users user_id | name Table#2 - user_categories id | user_id | category_id Table#3 - user_cities id | user_id | city_id Table#4 - user_dates id | user_id | dates_available Table#5 - categories category_id | category_name Table#6 - cities city_id | city_name Table#7 - provinces province_id | province_name Table#8 - categories country_id | country_name Each user will have multiple categories, cities and available dates listed in these tables. I simply want to retrieve and list each user and their data on a page. Here's my query. $url_city = 1; $url_category = 2; $url_date = '2021-07-19'; $find_records = $db->prepare("SELECT user_categories.*, categories.*, user_cities.*, cities.*, provinces.*, countries.*, user_dates.*, users.* FROM users LEFT JOIN user_categories ON users.user_id = user_categories.user_id LEFT JOIN user_cities ON users.user_id = user_cities.user_id LEFT JOIN user_dates ON users.user_id = user_dates.user_id LEFT JOIN categories ON user_categories.category_id = user_categories.category_id LEFT JOIN cities ON user_cities.city_id = cities.city_id LEFT JOIN provinces ON cities.province_id = provinces.province_id LEFT JOIN countries ON provinces.country_id = countries.country_id WHERE user_cities.city_id = :city_id AND user_categories.category_id = :category_id AND user_dates.date_available = :date_available GROUP BY users.user_id"); $find_records->bindParam(':city_id', $url_city); $find_records->bindParam(':category_id', $url_category); $find_records->bindParam(':date_available', $url_date); $find_records->execute(); $result_records = $find_records->fetchAll(PDO::FETCH_ASSOC); if(count($result_records) > 0) { foreach($result_records as $row) { $user_id = $row['user_id']; $name = $row['name']; $country_id = $row['country_id']; $country_code = $row['country_code']; $country_name = $row['country_name']; $province_id = $row['province_id']; $province_code = $row['province_code']; $province_name = $row['province_name']; $city_id = $row['city_id']; $city_name = $row['city_name']; $category_id = $row['category_id']; $category_name = $row['category_name']; } } There are no errors but the above query would only return a single row with only 1 "user" despite having multiple users in the "users" table. If I remove the GROUP BY, then it'll return multiple rows of the same user instead of all the relevant users. So what do you think I am doing wrong with my query? Edited July 20 by imgrooot
Basically I want to add up multiple tables and display a grand total on my page when the radio button is pressed. The radio button has values that connect to my database and the values link to and ID with a price. How can I use this code in order to work out a grand total? Many thanks. I have searched everywhere but found nothing. 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! 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! http://paste.ee/p/OhiWv
The above is a link to a readable version of my code. The XMLHTTPREQUEST worked, and the array was pulled down. Was able to print out the undecoded/unparsed array. However, immediately afterwards, all code stops working.
<script> var xhr; if (window.XMLHttpRequest) { // Mozilla, Safari, ... xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE 8 and older xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("POST", "PHPLibrary/selectMemberResults.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(); xhr.onreadystatechange = display_data; var $phparray function display_data() { if (xhr.readyState == 4) { if (xhr.status == 200) { //alert(xhr.responseText); $phparray = xhr.responseText; document.getElementById("suggestion").innerHTML = $phparray; // // //......................................................? // The above line of code is the last thing to print or // to do anything that returns to the browser.... //.......................................................? // All lines below do nothing............................? // } else { //alert('There was a problem with the request.'); } } } document.write("Length of phparray Array :" + $phparray.length + "<"); var output = JSON.parse($phparray, function (key,val) { if ( typeof val === 'string' ) { // regular expression to remove extra white space if ( val.indexOf('\n') !== -1 ) { var re = /\s\s+/g; return val.replace(re, ' '); } else { return val; } } return val; } ); document.write("Length of Array :" + $output.length + "<"); for (var i=0; i < $output.length; i++) { document.getElementById("suggestion").innerHTML = $output[i].MEMBER_NAME; } </script> i dont understand what is wrong plz help me.
here is code
$name = "img/".rand(1,9999999).".png"; $myFile = $name; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $html; fwrite($fh, $stringData); fclose($fh); $file=$name; $fst=file_get_contents($file); $im=imagecreatefromstring($fst); imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_NEGATE); //Convert to Grey Scale for($i=0;$i<123;$i++){ for($j=0;$j<50;$j++){ $px=imagecolorat($im,$i,$j); if($px<0x303030){ imagesetpixel($im,$i,$j,0); }else{ imagesetpixel($im,$i,$j,0xffffff); } } } $database = unserialize(@file_get_contents("db.txt")); if($database === false) $database = array(); // modify the database if needed if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($_POST['submit'] == 'Add') $database[$_POST['ident']] = substr($_POST['letter'], 0, 1); if($_POST['submit'] == 'Del') unset($database[$_POST['ident']]); if($fh = @fopen('db111.txt', 'w+')){ fwrite($fh, serialize($database)); fclose($fh); } }else{ $newimage = true; } $width = 130; $height = 40; $captcha_gridstart =1; $captcha_gridspace =2; $letters = findletters($im, $width, $height, $captcha_gridstart, $captcha_gridspace); $count = count($letters); $cellw = ($count > 0) ? intval(100 / $count) : 0; //dispeckle the image and GET co-ordinates of the characters of captcha image and return them. function findletters($image, $width, $height, $gridstart, $gridspace){ $offsets = array(); $o = 0; $atstartx = true; for($x = 0; $x < $width; $x++){ $blankx = true; for($y = 0; $y < $height; $y++){ if(imagecolorat($image, $x, $y) == 0){ $blankx = false; break; } } if(!$blankx && $atstartx){ $offsets[$o]['startx'] = $x; $atstartx = !$atstartx; }else if($blankx && !$atstartx){ $offsets[$o]['endx'] = $x; $atstartx = !$atstartx; $o++; } } $count = $o; for($o = 0; $o < $count; $o++){ for($y = 0; $y < $height; $y++){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['starty'] = $y; break; } } for($y = $height-1; $y > $offsets[$o]['starty']; $y--){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['endy'] = $y; break; } } } for($o = 0; $o < $count; $o++){ $offsets[$o]['ident'] = ""; for($x = $offsets[$o]['startx'] + $gridstart; $x < $offsets[$o]['endx']; $x += $gridspace){ for($y = $offsets[$o]['starty'] + $gridstart; $y < $offsets[$o]['endy']; $y += $gridspace){ $offsets[$o]['ident'] .= ((imagecolorat($image, $x, $y) == 0) ? "0" : "1"); #echo $offsets[$o]['ident'].'<br>'; } } } return $offsets; } $a=""; foreach($letters as $letter){ $asciiletter = $database[$letter['ident']]; if(!empty($asciiletter)) { $a.=$asciiletter; } } I need bit of help, so I am looking into a plugin created for newsletter where default is it shows ad but it has option to remove ads by checking the check box. Default is to send ads in newsletter but if you don't want to send ads through newsletter then check the box. The problem is, it seems like checkbox selected is not being picked up. Some help would be appreciated. The custom field in wp:
'label' => 'Hide newsletter ads', 'name' => 'hide_ads', 'type' => 'checkbox', 'instructions' => 'Checking the checkbox will remove ads', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'choices' => array( 'Hide newsletter ads' => 'Hide newsletter ads', ), 'allow_custom' => 0, 'default_value' => array( ), 'layout' => 'block', 'toggle' => 0, 'return_format' => 'value', 'save_custom' => 0, ),
This is the php code for it: <!doctype html> <html lang="en-GB"> <head> <meta name="viewport" content="width=device-width" /> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="x-apple-disable-message-reformatting"> <title><?php the_title(); ?></title> <style> <?php require ABSPATH . 'path/newsletter.css'; ?> </style> <!--[if mso]> <style type="text/css"> .outlook-fallback-font { font-family: 'Lucida Bright', 'Cambria', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; } </style> <![endif]--> </head> <?php $hide_newsletter_ads = get_field('hide_ads'); echo $hide_newsletter_ads; ?> <body itemscope itemtype="http://schema.org/EmailMessage"> <div class="wrap"> <?php if (!$hide_newsletter_ads) { include ABSPATH . 'path/ad-banner.php'; } ?> <div class="header"> <a href="<?php bloginfo( 'url' ); ?>"> <img src="<?php echo get_home_url().'logo.png' ?>" alt="News" /> </a> </div> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( get_field( 'newsletter_summary' ) ) { ?> <div class="newsletter-summary"><?php the_field( 'newsletter_summary' ); ?></div> <?php } ?> <?php if ( have_rows( 'newsletter_content' ) ) : ?> <?php // Loop through the ACF blocks $count = 0; while ( have_rows( 'newsletter_content' ) ) : the_row(); if ( get_row_layout() === 'story' ) : ?> <?php if ( 0 === $count ) { ?> <span class="date outlook-fallback-font"><?php the_time( 'd M Y' ); ?></span> <?php } ?> <?php if ( get_sub_field( 'story_heading' ) ) : ?> <h1><?php the_sub_field( 'story_heading' ); ?></h1> <?php endif; ?> <div class="content"> <?php the_sub_field( 'story_content' ); ?> </div> <?php endif; if ( 'post_list' === get_row_layout() ) : ?> <?php $posts = get_sub_field( 'post_list' ); if ( $posts ) : ?> </div> <div class="story-list"> <h2><span class="wrap"><?php the_sub_field( 'post_list_heading' ); ?></span></h2> <div class="wrap-table"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <?php // Output story cards foreach ( $posts as $i => $post ) { if ( 0 === $i % 2 ) { echo '<tr>'; } $class = ( 0 === $i % 2 ) ? 'odd' : 'even'; $image_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( 640, 345 ) ); $image_srcset = wp_get_attachment_image_srcset( get_post_thumbnail_id( $post->ID ) ); echo sprintf( '<td class="story-cell %4$s" valign="top"> <a href="%1$s" class="story-card outlook-fallback-font"> <img src="%3$s" alt="" height="120" style="height: 150px; object-fit: cover;" /> <span>%2$s</span> </a> </td>', esc_url( get_permalink( $post->ID ) . '?utm_source=newsletter&utm_medium=email&utm_campaign=newsletter' ), // permalink esc_html( get_the_title( $post->ID ) ), // title // esc_attr( $image_src[0] ), // image - src esc_attr( $image_src[0] ), // image - src esc_attr( $class ) // class ); if ( 0 !== $i % 2 || count( $posts ) === ( $i + 1 ) ) { echo '</tr>'; } } ?> </table> </div> </div> <div class="wrap"> <?php endif; endif; if (!$hide_newsletter_ads) { (0 === $count) { include ABSPATH . 'path/mpu-1.php'; } if (1 === $count) { include ABSPATH . 'path/mpu-2.php'; } } $count++; endwhile; endif; ?> <div class="footer"> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td align="left"> © <?php echo esc_html( date( 'Y' ) ); ?> </td> <td class="footer-link"> <a href="<?php echo get_permalink( get_page_by_path( 'privacy-policy' ) ); ?>">Privacy Policy</a> · <a href="%unsubscribe_url%">Unsubscribe</a> </td> </tr> </table> </div> </div> <?php endwhile; endif; ?>
I'm trying to turn this while loop into a for loop and am unable to get my result set to display properly in the for loop. The while works fine I just want to be able to have more control over which information is shown in my table as I loop and was wanting to use a for loop that way I can take advantage of the counter variable while i"m displaying my information. Any help would be appreciated. while ($row = mysql_fetch_assoc($data_result_set)) { echo "<td>".$row["product_id"]."</td>"; echo "<td>".$row["city"]."</td>"; echo "<td>".$row["quantity"]."</td>"; } *** I'm wanting it to look like something like this but can't figure out how to properly work in which row to display with the $i variable. $count=mysql_num_rows($data_result_set); for($i = 0; $i <= $count; $i++){ echo "<td>".mysql_fetch_assoc[$i]["product_id"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["city"]."</td>"; echo "<td>".mysql_fetch_assoc[$i]["quantity"]."</td>"; } I know the syntax for the for loop is totally off with the method mysql_fetch_assoc just dropped in there like a jerk but I'm just kinda pseudoing it out. Any help would be appreciated. Thanks in advance. When I echo the POST, it echoes the correct value. The MySQL portion seems to just ignore it all together. I've tried changing the dropdown option to just a text field, same thing occurred. I have text fields right above this particular one that update just fine with the SAME exactly scripting. if POST, update query, done. Works. This one for some reason will not. MySQL portion: if ($_POST['bUpdate']){ mysql_query("UPDATE `Patients` SET `b` = '$_POST[bUpdate]' WHERE `id` = '".$_GET['id']."'"); } echo $_POST['bUpdate']; Form Portion: Code: [Select] <tr onmouseover="color(this, '#baecff');" onmouseout="uncolor(this);"> <td width="310" colspan="2" align="center"><span class="fontoptions">Postcard Status </span><br /> <? if ($data['b'] == 1){ echo '<select name="bUpdate"><option value="1" selected>Yes</option><option value="0">No</option></select>'; } else { echo '<select name="bUpdate"><option value="1">Yes</option><option value="0" selected>No</option></select>'; } ?> </td> </tr> Hi, I have the following file structure /.htaccess /index.php /displaypage.php All files are on root. I have following written in .htaccess file Options FollowSymLinks RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([a-z0-9-]+)$ displaypage.php?page=$1 [NC,L] I have following written in displaypage.php echo $_GET["page"]; Now when I run http://localhost/ then it shows index.php page which is correct. If I run http://localhost/something then it shows a blank page. Previously it used to display that "page" variable on screen. mod_rewrite is enabled and I am using Windows with XAMPP. What am I doing wrong? Thanks I just did a huge import from an app I have been working on. No issues except for this. I uploaded & imported all files & databases from my wampserver (localhost, local server) to my main online server. Before I continue with the problem, I have to give you info on how the files work. I am using a "controller" to view the files. Meaning, from index.php, I call all the files. For example, instead of mysite.com/register.php, its mysite.com/index.php?page=register. The index defines the doctype & html tags etc. The other files that are called through index.php are just pure php code, it does not contain the head & body tags etc. So, the issue is , when the surfer submits a form, i need to set a cookie. this cookie is VERY important. I cannot get it to work. I am getting the header warnings after submit Of course, this is to be expected. But I tried it on my local server, & it worked. I am not very familiar with cookies, this is a side of PHP i never really even touched. I know almost everything but that. So the php code is before the html code on the page, so I figured it was worth a shot. Im guessing the problem here is, since the code being outputted as index.php code + the form page code. So the cookie is being set after the html tags. How can I fix this? I need it to work thru the controller. I cannot just make it a single file, all files on the site needs to be thru this controller, otherwise it will mess everything up. Ino I could just add the code from index.php plus the form page code & just run the php code before all of the html tags, but like I said it has to be called thru index.php. I appreciate your replies, & I hope you guys dont think im an idiot & can understand my question, im terrible with words! 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 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> 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> |