PHP - Displaying Recoirds If 2 Tables
I want to display a bunch of records from table 1. Table 1 has a field called "user_id".
In table 2 i have id and name. Hoiw do I query table 1 and then display the name of the user? I have $query = "SELECT * from table1 where status = '$status' ORDER by ????"; $results = mysql_query($query); while $row = $mysql_fetch_array($results){ echo "status is "$row['status']." and work type is ".$row['work_type']. "for the user" $row['name']."<br>""; } Obviosuly thius wouldnt work but basically I want to pull everything fromt able 1, but sort by the name which is located in table 2. The only thing I need from table two is the name associated with user_id. Oh I ALSO want to keep all records from table1 with the same user_id on 1 line (users in table2 are unique)! Similar TutorialsSo I have 3 tables, student, student_course and course. I'm only using student and course atm, probably should look into student_course haha well those are the tables provided to us for the project I'm working on. I'm trying to list all the courses from the course table and then when clicking on a course I want to display all the students who registered for this course( which would probably be the student table) Here is my code for displaying the courses: Code: [Select] <?php $display_sql ="SELECT cname FROM course ORDER BY cid DESC"; $display_query = mysql_query($display_sql) or die(mysql_error()); $rsDisplay = mysql_fetch_assoc($display_query); ?> <html> <head> </head> <body> <p> Click course to display all students registered for that course</p> <?php do { ?> <p><a href="test.php?cname=<?php echo $rsDisplay['cid']; ?>"> Course: <?php echo $rsDisplay['cname']; ?> </a> </p> <?php } while ($rsDisplay = mysql_fetch_assoc($display_query)) ?> And here is my code for displaying the students from the student table registered for the specific course you click on: Code: [Select] <?php $q = "SELECT * FROM student WHERE cname = $_GET[cname]"; $confirm_query = mysql_query($q); $rsconfirm = mysql_fetch_assoc($confirm_query); ?> <html> <head> </head> <body> <p> Displaying all student </p> <p> First Name <?php echo $rsconfirm['sname']; ?> </p> <p> Surname: <?php echo $rsconfirm['fname']; ?> </p> I'm very new to php. Im using "test.php?cname=" to transfer the cname (course name) info from my course table to the next page where I use $_GET[cname]";. cname isn't a primary key in my table, rather just a row. Can it be done like that? Or should you just use primary keys? I managed to display the courses but when clicking it, it wont display the registered users and gives me an error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-5.3.3\www\Project\test.php on line 28 What does that mean? Line 28 is this part : Code: [Select] $q = "SELECT * FROM student WHERE cname = $_GET[cname]"; //26 $confirm_query = mysql_query($q); //27 $rsconfirm = mysql_fetch_assoc($confirm_query); //28 Any criticism welcome. When coding I'm still trying to figure out what it is I'm doing nevermind getting it to work haha. Thanks in advance Hello guys, I'm trying to figure out how to display and image that is located in one table (profile) and make it correspond to a variable on another table (latest_post) to where you echo out the variable from the table(latest_post) and the image from table(profile) appears next to the post. any how here is my code: Code: [Select] <?php $query = mysql_fetch_array(mysql_query("SELECT person FROM latest_post AND avatar_img FROM profile WHERE id FROM latest_post = id FROM profile ")); echo $query['avatar_img']; ?> Also when echoing out the query I only get the name of the image and not the image this is most likely because my image is stored in a different folder right? Thanks in advance, your help is much appreciated since I'm barely a beginner at php and MySQL. Below is a page which is supposed to output the name, blog contribution and picture of contributing members of a website. <div id="blog_content" class="" style="height:90%; width:97%; border:5px solid #c0c0c0; background-color: #FFFFFF;"> <!--opens blog content--> <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //include the config file require_once("config.php"); //Define the query. Select all rows from firstname column in members table, title column in blogs table,and entry column in blogs table, sorting in ascneding order by the title entry, knowing that the id column in mebers table is the same as the id column in blogs table. $sql = "SELECT blogs.title,blogs.entry,members.firstname,images.image FROM blogs LEFT JOIN members ON blogs.member_id = members.member_id LEFT JOIN images ON blogs.member_id = images.member_id ORDER BY blogs.title ASC "; $query = mysql_query($sql); if($query !== false && mysql_num_rows($query) > 0) { while(($row = mysql_fetch_assoc($query)) !== false) { echo '<div id="blog_content1" style="float:left; position:relative;bottom:18px;left:13px; background-color: #FFFFFF; height:16.7%; width:100%; border:0px none none;" <!--opens blog_content1 same as main center top 1 and 2 from index page everything scaled down by a factor of 3, heightwise--> <div class="red_bar" style="height:3%; width:100%; border:1px solid #959595;"> <!--a--> <div class="shade1" style="height:5px; width:100%; border:0px none none;"> </div> <div class="shade2" style="height:5px; width:100%; border:0px none none"> </div> <div class="shade3" style="height:5px%; width:100%; border:0px none none"> </div> </div> <!-- closes red bar--> <div class="content" style="height:28.3%; width:100%; border:0px none none;"> <!----> <div class="slideshow" id="keylin" style="float:left; width:20%; border:0px none none;"> <!--a--> <div><img header("Content-type: image/jpeg"); name="" alt="" id="" height="105" width="105" src="$row[image]" /></div> </div> <!-- closes pic--> <div class="content_text" style="float:right; position:relative;top:7px;left:0px; max-height:150px; width:78.5%; border-width:4.5px; border-bottom-style:solid; border-right-style:solid; border-color:#c0c0c0; "> <!--a-->'; echo "<h3>".$row['title']."</h3>"; echo "<p>" .$row['entry']."<br />".$row['firstname']."</p>"; echo '</div> <!-- closes content text--> </div> <!-- closes content--> </div> <!-- closes blog_content1-->'; } } else if($query == false) { echo "<p>Query was not successful because:<strong>".mysql_error()."</strong></p>"; echo "<p>The query being run was \"".$sql."\"</p>"; } else if($query !== false && mysql_num_rows($query) == 0) { echo "<p>The query returned 0 results.</p>"; } mysql_close(); //Close the database connection. ?> </div> <!-- closes blog content--> The select query is designed to retrieve all the blog contributions(represented by the fields blogs.title and blogs.entry) from the database, alongside the contributing member (member.firstname) and the member's picture(images.image), using the member_id column to join the 3 tables involved, and outputs them on the webpage. The title, entry and firstname values are successfully displayed on the resulting page. However, I can't seem to figure out how to get the picture to be displayed. Note that the picture was successfully stored in the database and I was able to view it on a separate page using a simple select query. It is now just a question of how to get it to display on this particularly crowded page. Anyone knows how I can output the picture in the img tag? I tried placing the header("Content-type: image/jpeg"); statement at the top of the php segment, then just right below the select query and finally just right above the img tag, but in every case, I just got a big white blank page starring at me. How and where should I place the header statement? And what else am I to do to get this picture displayed? Any help is appreciated. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=308347.0 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! Okay, so I am trying to display players usernames and kills and deaths from my highscores page and I have different div classes set for each block This is my code:
<div id="table"> <div class="tr ttl"> <div class="col st1">Rank</div> <div class="col st2">Username</div> <div class="col st3">Rating</div> <div class="col st4">Deaths</div> <div class="col st5">Kills</div> </div> <?php if($_GET['skill'] == 0) { $skill = $_GET['skill']; $page = ($_GET['page']-1); $limit = RESULTS_PER_PAGE*$page.', '.RESULTS_PER_PAGE; $limitt = RESULTS_PER_PAGE*$page; $query = "SELECT * FROM hs ORDER BY `elo` DESC LIMIT ".$limit.""; $result = mysql_query($query); $counter = 1; while ($fetch = mysql_fetch_assoc($result)) { echo '<div class="tr normal ftr rd1"> <div class="col st1">'.($counter+$limitt).'</div> <div class="col st2"><a href="?user='.$fetch['username'].'">'.$fetch['username'].'</a></div> <div class="col st3">'.number_format($fetch['kills']).'</div> <div class="col st4">'.number_format($fetch['deaths']).'</div> <div class="col st5">'.$fetch['elo'].'</div> </div> '; $counter++; } } ?>See where it says echo '<div class="tr normal ftr rd1"> I'd want it to print out like this: (tr normal ftr rd1) for the first one, (tr normal ftr rd2) for second one and (tr normal ftr rd3) for the 3rd one. Then (tr normal) and (tr odd normal) for the rest Can anyone help me out here? I'm trying to grab something on a different page with the layout: Code: [Select] 0 day, 10 hours, 35 min, 59 sec My code to display this information on another page is: <?php $page_contents = file_get_contents("http://www.mysite.com"); $matches = array(); preg_match('/([0-9,]+) day, ([0-9,]+) hours, ([0-9,]+) min, ([0-9,]+) sec /', $page_contents, $matches); echo $matches[0]; ?> Why is it displaying nothing? Quick background... I bought an auction program with plenty of bugs. Todays bug that I can't figure out is that it is displaying a - (dash) when I would prefer it to display 0 (zero) in instances of "total fees due" or in the "fee chart" if it's a flat fee of 0. 0% works fine. The code related to it is spread out on a handful of files but I think it's mostly related to the following. if (is_array($setup_fee)) { foreach ($setup_fee as $key => $value) { if ($value['amount']) { if ($value['calc_type'] == 'flat') { $output['amount'] += $value['amount']; $fee_display = $this->display_amount($value['amount'], $this->setts['currency']); } else if ($value['calc_type'] == 'percent') { $output['amount'] += $this->round_number($item_details['start_price'] * $value['amount'] / 100); $fee_display = $value['amount'] . '%'; } if ($item_relist) { $output['amount'] = $this->round_number($output['amount'] - $output['amount'] * $this->fee['relist_fee_reduction'] / 100); } $output['display'] .= '<tr class="c1"> '. ' <td width="150" align="right"><b>' . GMSG_SETUP_FEE . ':</b></td> '. ' <td align="left" nowrap colspan="2"><b>' . $fee_display . $value['display'] . '</b></td> '. '</tr> '; ## now add the row on the invoices table if ($user_payment_mode == 2 && $add_invoices) { $account_balance += $output['amount']; $tax_settings = $this->tax_amount($output['amount'], $this->setts['currency'], $user_details['user_id'], $this->setts['enable_tax']); $sql_insert_invoice = $this->query("INSERT INTO " . DB_PREFIX . "invoices (user_id, item_id, name, amount, invoice_date, current_balance, can_rollback, tax_amount, tax_rate, tax_calculated, reverse_id) VALUES ('" . $user_details['user_id'] . "', '" . $item_details['auction_id'] . "', '" . GMSG_SETUP_FEE . "', '" . $output['amount'] . "', '" . CURRENT_TIME . "', '" . $account_balance . "', " . $can_rollback . ", '" . $tax_settings['amount'] . "', '" . $tax_settings['tax_rate'] . "', '1', '" . $item_details['reverse_id'] . "')"); $sql_update_user_balance = $this->query("UPDATE " . DB_PREFIX . "users SET balance='" . $account_balance . "' WHERE user_id='" . $user_details['user_id'] . "'"); } } } } foreach ($fees_no_tier as $key => $value) { if ($value[1]) { $fee_details = $this->display_fee($key, $user_details, $item_details['category_id'], $item_details['list_in'], $voucher_details, $apply_tax); if ($item_relist) { $fee_details['amount'] = $this->round_number($fee_details['amount'] - $fee_details['amount'] * $this->fee['relist_fee_reduction'] / 100); } $output['amount'] += $fee_details['amount']; if ($fee_details['amount']) ## only do this if there is a fee { $output['display'] .= '<tr class="c1"> '. ' <td width="150" align="right"><b>' . $value[0] . ':</b></td> '. ' <td nowrap colspan="2"><b>' . $fee_details['display'] . '</b></td> '. '</tr> '; ## now add the row on the invoices table if ($user_payment_mode == 2 && $add_invoices) { $account_balance += $fee_details['amount']; $tax_settings = $this->tax_amount($fee_details['amount'], $this->setts['currency'], $user_details['user_id'], $this->setts['enable_tax']); $sql_insert_invoice = $this->query("INSERT INTO " . DB_PREFIX . "invoices (user_id, item_id, name, amount, invoice_date, current_balance, can_rollback, tax_amount, tax_rate, tax_calculated, reverse_id) VALUES ('" . $user_details['user_id'] . "', '" . $item_details['auction_id'] . "', '" . $value[0] . "', '" . $fee_details['amount'] . "', '" . CURRENT_TIME . "', '" . $account_balance . "', " . $can_rollback . ", '" . $tax_settings['amount'] . "', '" . $tax_settings['tax_rate'] . "', '1', '" . $item_details['reverse_id'] . "')"); $sql_update_user_balance = $this->query("UPDATE " . DB_PREFIX . "users SET balance='" . $account_balance . "' WHERE user_id='" . $user_details['user_id'] . "'"); } } } } $output['display'] .= '<tr class="c5"><td colspan="3"></td></tr><tr class="c2"> '. ' <td width="150" align="right"><b>' . GMSG_TOTAL . ':</b></td> '. ' <td nowrap colspan="2"><b>' . $this->display_amount($output['amount'], $this->setts['currency']) . '</b></td> '. '</tr> '. '<tr class="c5"> '. ' <td><img src="themes/' . $this->setts['default_theme'] . '/img/pixel.gif" width="150" height="1"></td> '. ' <td colspan="2"><img src="themes/' . $this->setts['default_theme'] . '/img/pixel.gif" width="1" height="1"></td> '. '</tr> '; return $output; } I'll really really appreciate the help. Hi, can someone help me understand why it 's only printing the first record in the database ? Code: [Select] <?php require_once("functions.php"); ?> <!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>Untitled Document</title> </head> <body> <?php DatabaseConnection(); mysql_select_db("auntievics"); $query= "SELECT product_id FROM treats"; $result_set= mysql_query($query); if ($result_set){ $products= mysql_fetch_row($result_set); foreach ($products as $value){ print $value; } print "<br />"; } //print_r(mysql_fetch_row($result_set)); ?> </body> </html> This is a multiplication test for students to take and when they finish they click the score button. after they click the score button it tells them what their score is, with the opportunity to take it again. What I am trying to do is make this able to keep the recent score and just post the next score. Right now my app just gives the first score and then when I take the test again it just refreshes and gives the new score. I want it to play the new score under the old score. I can't seem to figure out how to do this. If someone could help point me in the right direction. Would appreciate the help. Here is my code for my app.... Code: [Select] <?php require_once('database.php'); define ('ROWS', 3); define ('COLS', 3); define ('MAX_NUMBER', 12); date_default_timezone_set('America/New_York'); if (isset($_POST['btn_score'])) { $result_name= $_POST['result_name']; $correct = 0; //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" && $problem <> "result_name") { //echo "$problem -- $answer <br />"; $problem = explode('_', $problem); $num1 = $problem[2]; $num2 = $problem[3]; $right = $num1 * $num2; if ($answer != $right) { echo "$num1 * $num2 = $answer , The right answer is $right<br />"; }else { $correct = $correct + 1; } } } $result_score= 0; $result_score= ($correct / 9) * 100; echo "your score is <br/>$result_score<br/>"; } $sql = "INSERT INTO results (result_name, result_score, result_date_time) VALUES ('$result_name','$result_score', NOW());"; ?> <h1>Multiplication Test</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>"; ?> Hi. I have this code which input data to the database. Code: [Select] <?php include("connect.php"); echo $date = date("Y-m-d H:i:s"); echo "\n <br />"; echo $date2 = date('Y-m-d H:i:s', strtotime("+20 seconds")); mysql_query("UPDATE users2 SET date2 = '$date2'"); $query = mysql_query("SELECT date2 FROM users2"); $numrows = mysql_num_rows($query); if ($numrows != 0) { while ($row = $mysql_fetch_array($query)) { $date_final = $row['date2']; } } echo $date_final; ?> Variable date2 is stored as timestamp. Now i want to display this two variable on the web, but this code doesn't work. Why? Thank you. hi guys I am having trouble displaying a table in a mySQL database i get the error message Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in /home/students/accounts/s7188633/hit3323/www/htdocs/Assiment2V2/main.php on line 47 Warning: mysqli_fetch_row() expects parameter 1 to be mysqli_result, boolean given in /home/students/accounts/s7188633/hit3323/www/htdocs/Assiment2V2/main.php on line 53 these are the two line that it realtes to row 47: $Row = mysqli_fetch_row($result); row 53: $Row = mysqli_fetch_row($result); below is all the code if you wanted to look at it, thanks <?php $choice = addslashes ($_POST["selection"]); { $DBConnect = @mysqli_connect("neptune.it.swin.edu.au", "*****", "***") Or die("<p>Unable to connect to the database server.</p>" . "<p>Error code " . mysqli_connect_errno() . ": " . mysqli_connect_error()) . "</p>"; $DBName = "*****_db"; if (!@mysqli_select_db($DBConnect, $DBName)) echo "<p>The database is not available.</p>"; $SQLstring = "SELECT * FROM Books";// WHERE category = 'Programing'"; $QueryResult = @mysqli_query($DBConnect, $SQLstring) Or die("<p>Unable to execute the query.</p>" . "<p>Error code " . mysqli_errno($DBConnect) . ": " . mysqli_error($DBConnect)) . "</p>"; $NumRows = mysqli_num_rows($QueryResult); if ($NumRows == 0) echo "<p>No records returned.</p>"; else { mysqli_select_db($DBConnect, $DBName); $SQLstring = "SELECT * FROM Books"; $result = @mysql_query($DBConnect, $SQLstring); $Row = mysqli_fetch_row($result); do { echo "<tr><td>{$Row[0]}</td>"; echo "<td>{$Row[1]}</td>"; echo "<td align='right'>{$Row[2]}</td>"; echo "<td align='right'>{$Row[3]}</td></tr>"; $Row = mysqli_fetch_row($result); } while ($Row); } } mysqli_close($DBConnect); ?> <?php include'db.php'; $session= $_SESSION['username']; $query="SELECT * FROM login_ip WHERE login='$session'"; $result= mysql_query($query); $count= mysql_num_rows($result); //$close = die($query); $min= $count - 1; $find= mysql_query("SELECT * FROM login_ip WHERE login= '$session' & times='$min'")or die(mysql_error()); while($row = mysql_fetch_assoc($find)) { $lip=$row['ipaddress']; echo" <br>$min<br>$count"; } ?> i worte the code above to pull the last ip address that a user has login form it is finding the ip adress but it is displaying like this Code: [Select] 72.145.25.457 72.145.25.457 72.145.25.457 72.145.25.457 72.145.25.457 so i remove the $lip form the echo and place $min and $count in there and i am getting Code: [Select] 1 2 1 2 1 2 1 2 Can some one please enplane why i am getting this problem thank you I am trying to make a PHP script that will read the linked file. It essentially is a map array using ASCII charactor codes. It has a 23 offset initial line for the name of the map, and then 76 offset for each row of the map. Half the 76 is for the actual map displaied ASCII chr and the other half for the color. I would think it would be fairly easy to do, but I can't seem to get the code to work. http://cid-b676d7f6bbd68862.office.live.com/self.aspx/.Public/file.map Anyone have some puesdo code to help me out. So I am trying to display an image from a database (I know it's not the best idea but it's what I was told to do). Anyway I'm having problems displaying it. Here is the code for displaying the image. $cat = $_GET['cat']; include 'includes/openDbConn.php'; $sql = 'SELECT * FROM CushionsCategories WHERE CushionCategory = "'.$cat.'"'; echo $sql; $result = mysql_query($sql); echo '<table>'; while($val = mysql_fetch_assoc($result)){ $cush = 'SELECT * FROM Cushion WHERE SKU = "'.$val['CushionSKU'].'"'; echo $cush; $cushres = mysql_query($cush); $cushval = mysql_fetch_assoc; $img = 'SELECT * FROM Images WHERE SKU = "'.$val['CushionSKU'].'"'; echo $img; $imgres = mysql_query($img); $imgval = mysql_fetch_assoc($imgres); if( $i % 3 == 0 ) { echo '</tr><tr>'; } echo '<td><img src="image.php?sku='.$val['CushionSKU'].'" name="'.$imgval['FileName'].'" description="'.$imgval['Description'].'" /></td>'; } echo '</tr></table>'; and the page that gets the image: $sql = 'SELECT Image FROM Images WHERE SKU = "'.$sku.'"'; //echo $sql; $result = mysql_query($sql) or die("Invalid query: " . mysql_error()); // set the header for the image header("Content-type: image/jpeg"); echo mysql_result($result, 0); Thanks for any help in advance. I have about 7 fields in one of my tables. Some of the fields are null or blank since they arent required (like address2) Is their a better way of formatting an address rather than doing something like: <?php while ($row = mysql_fetch_array($query)) { if ($row['address2'] != "") { echo $row['address2'] . "<br/"; } if ($row['otherField'] != "") { echo $row['otherField'] . "<br/"; } if ($row['anotherField'] != "") { echo $row['anotherField'] . "<br/"; } } ?> I have more fields than just address2, I just don't want a bunch of if statements Is it possible to do either one of the following: - Display all current sessions that are set or even request a session from one client and display it to another client. - Or else to detect when someone closes their browser. Thanks in advanced! - GreenFanta I put the javascript code of ad into a file named ad.html, then call it in php by $ad = file_get_contents("http://mysite.com/ad.html"); echo $ad; But this does not work for file_get_contents("/ad.html") Is there a way to avoid writing the domain name, and just getting the ad from the file in the root folder? |