PHP - Simple Table Problem
Can anybody see how to fix the table below. My results are being stacked horizontally rather than vertically. I have attached a picture for you to see what I mean.
Thanks //SKILL - query the database table $sql="SELECT Skill_Name, Rating FROM resource_skill ln inner join skill n on ln.Skill_ID = n.Skill_ID WHERE ln.Resource_ID=" . $contactid; //SKILL - run the query against the mysql query function $result=mysql_query($sql) or die(mysql_error() . '<br />' . $sql); echo "<table id=skill>"; echo "<tr>"; echo "<th>Skill</th>"; echo "<th>Rating</th>"; echo "</tr>"; //create while loop and loop through result set while($row=mysql_fetch_array($result)){ $Skill_Name=$row['Skill_Name']; $Rating=$row['Rating']; //display the result of the array echo "<ul>\n"; echo "<td>" . "" .$Skill_Name . " <td>" . $Rating . "</td></td>\n"; echo "</ul>"; } } echo "</tr>"; echo "</table>"; ?> Similar TutorialsOk, so I have some code that takes the records in my database and outputs them in a table, but currently after the first record it starts spacing them incorrectly
Here is the code
<?php require_once('config.php'); require_once('menu.php'); echo '<h1>View All Alien Interactions</h1>'; echo '<table> <tr>'; foreach($fields AS $label){ echo "<th>{$label}</th>"; } echo '<th>Edit</th><th>Delete</th>'; echo '</tr>'; $fields_str = '`contact_id`, `'.implode(array_keys($fields), '`, `').'`'; $sql = "SELECT {$fields_str} FROM `alien_abduction`"; foreach($dbh->query($sql) as $row) { echo '<tr>'; foreach($fields AS $field=>$value){ echo '<td>'.(isset($row[$field]) && strlen($row[$field]) ? $row[$field] : ' '.'</td>'); } echo '</tr>'; echo '<td><a href="edit.php?contact_id='.$row['contact_id'].'">Edit</a></td>'; echo '<td><a href="delete.php?contact_id='.$row['contact_id'].'">Delete</a></td>'; echo '</tr>'; echo '</table>'; } ?>I just want it to start a new line after importing each record This is a picture of what its curently doing, look at the second row, it just keeps adding all additional entries on this line (I whited out personal info) Edited by tekkenfan2, 30 June 2014 - 01:06 PM. im a complete novice. im using one of the tutorials on here to make a simple search form. the bit of script that i think outputs the results is $results = array(); // the result array $i = 1; while ($row = mysql_fetch_assoc($searchResult)) { $results[] = "{$i}: {$row['placing']},   {$row['racedate']},   {$row['horseid']}<br /><br />"; $i++; how do i make these results appear in a table, and how would i make it so there was a link on the date that clicked would show all the races on that day? sorry i advance as this is probably the most dumb of questions! I have two mysql tables, one is called "posts", the other is called "removed_posts", I have joined them together and can get some of the information from the tables, but I want to be able to get all of the information. This is my query, and the variables I need the information to go to: Code: [Select] $quer = mysql_query("SELECT posts.id, removed_posts.post_id FROM posts, removed_posts WHERE posts.id=removed_posts.post_id AND removed_posts.user_id='".$session."'"); while($get_post = mysql_fetch_array($quer)) { $session = $_COOKIE['id']; $to_id = $get_post['to_id']; $from_id = $get_post['from_id']; $post = linkify(nl2br(htmlentities($get_post['post']))); $date = time_stamp($get_post['date']); $id = $get_post['id']; What that's doing is selecting the id from 'posts' table, and selecting the post_id from the 'removed_posts' table (The query checks to make sure posts.id is equal to removed_posts.post_id), it does that just fine, since I defined what information I wanted it to get in the query, however, now I need to get the other information which will come from the 'posts' table. $get_post['to_id'], $get_post['from_id'], $get_post['post'], and $get_post['date'] I hope that's not toooooo confusing, any help would be appreciated hi... i have a table ... i add and remove data in the table...when i add new record , information add to center of the table ! whats problem? i want add data in first of table. please guide me.thanks
I'd like to write - or acquire - code that displays a simple table (name, phone number, email address, plus a comments field) on a web page in a password-protected page and allows a user to add his own information, update it or delete it. I figure hundreds of people and companies have written something like this so I'd like to find either an example I can imitate or even an existing package that I can simply customize to the specifics for my own table. Can anyone help me with that? Or am I going to have to reinvent the wheel for the gazillionth time and write it myself? It shouldn't be that difficult I just don't know how to do it myself. I'm using the following code for a simple navigation, i has been placed in the content of my home page, it works fine however i don't know how to set the home page. <div id="content"> <?php $page = $_GET['page']; $file = $page.".php"; if(file_exists($file)) { include($file); } else { include "error.php"; } ?> </div> SOLVED, sorry. ... but i can't work it out. all i want to do is; if ( $this_item exists within the table ) { do a } else { do b } for example, $this_item = 'john', and i want the script to do (a) if he's in the table, or (b) if he isn't. thank you! This is my website: www.wearenip.com/home.html This is the menu that should appear on the left hand side, but doesn't: www.wearenip.com/menu.php This is my server's output saying that php is running just fine: http://wearenip.com/phpinfo.php I'm using this code in the left side bar div: Code: [Select] <?php include("menu.php"); ?> The PHP file will not display from the HTML file no matter what I do. I've tried using every possible combination of file linking including /menu.php ./menu.php and even the full http://www.wearenip.com/menu.php etc etc etc I'm genuinely upset about this. Any help would be greatly appreciated. PS: I can't get any PHP file to properly include in any HTML file on any computer I have. Nothing displays whatsoever regardless of what is in the PHP file, even if it's just a text word. Doesn't matter if it's hosted on a PHP compatible internet server or just on a local server or just on the local machine itself. Nothing. so I have an xml string the following expression $xpath = $response->xpath('/atom:feed/atom:entry/atom:content'); returns the following array SimpleXMLElement Object ( [@attributes] => Array ( [type] => application/vnd.google-earth.kml+xml ) [Placemark] => SimpleXMLElement Object ( [name] => M1 [description] => SimpleXMLElement Object ( ) [Style] => SimpleXMLElement Object ( [IconStyle] => SimpleXMLElement Object ( [Icon] => SimpleXMLElement Object ( [href] => http://maps.gstatic.com/intl/en_ALL/mapfiles/ms/micons/blue-dot.png ) ) ) [Point] => SimpleXMLElement Object ( [coordinates] => -79.395018,43.645423,0.0 ) ) ) However what I'm trying to get are the coordinates, but neither $xpath = $response->xpath('/atom:feed/atom:entry/atom:content/Placemark'); OR $xpath = $response->xpath('/atom:feed/atom:entry/atom:content/Placemark/child::*'); work I even tried just loading atom:content into an array and going from there no luck. Any ideas. Oh. BTW this might help http://code.google.com/apis/maps/documentation/mapsdata/developers_guide_protocol.html#RetrievingFeatures Simple for you, but I am very new to just messing around with mysql functions.
I have 1 table that tracks both the item id and the amount of views the item has.
The id column is called gId, and the views column is called gplays.
All I am trying to do is get it to show a list of the latest 100 items, but sort them as most viewed.
I've looked at online tutorials to googling the function, but can't find anything that works.
Here's my current code:
$results = $db->cachegetall(300, "SELECT gId id, gName name, gDescription descr, gThumb thumb, gplays plays FROM games ORDER BY gId DESC LIMIT 100");that just shows the latest 100. When I try ORDER BY gId DESC, gplays DESC LIMIT 100");I get nothing different. If I do ORDER BY gplays DESC LIMIT 100");I get the 100 results, but they are from all items, and I want to only get it from the latest 100 items. Can someone help me? I really have no idea what these functions are doing, other than the very basic tutorials I've read on the order by function. i am running a file in the following folder on my hosting server /httpdocs/folder1/folder2/script.pjp how do i include a file that is located at the root of the hosting server /httpdocs/globalFunctions.php iv tried $maindir = dirname(__FILE__) . DIRECTORY_SEPARATOR; require $maindir . DIRECTORY_SEPARATOR . "globalFunctions.php"; include('http://www.domainname.com/globalFunctions.php'); and include('../../globalFunctions.php'); but none of these work any ideas Gud pm! I need some help guys! I made this simple code to compare $check_location to $events['location'] every loop so if they are equal it should not echo what's inside the if statement.. Here's my code: Code: [Select] $events_set = select_all_events($mall_id, $month, $year, $public); while($events = mysql_fetch_array($events_set)) { $check_location = ""; if($check_location != trim($events['event_location'])) { $check_location = trim($events['event_location']); echo "<tr>"; echo "<td colspan=7 id='header'>"; echo "<br />"; echo $events['event_location']; echo "</td>"; echo "</tr>"; } before the loop is finished, $check_location must store a new events['location']... I know the problem is kinda simple but the comparison can't seem to work.. Thanks in advance! Hi all, Im coding a simple script for my website which just changes the users rank. Code: [Select] <?php session_start(); include "../includes/db_connect.php"; include "../includes/functions.php"; logincheck(); ini_set ('display_errors', 1); error_reporting (E_ALL); $username=$_SESSION['username']; $get = mysql_query ("SELECT * FROM users WHERE username = '$username'"); $fetch = mysql_fetch_object($get); if ($fetch->userlevel >= "2"){ $newrank = $_POST['newrank']; $user1 = $_POST['user']; if (strip_tags($_POST['update'])){ mysql_query("UPDATE users SET `rank` = '$newrank' WHERE username='$user1'") or die (mysql_error()); echo ("You have updated $user1's rank to $newrank !"); } } else{ echo ("Your userlevel isnt high enouth to be here!"); } ?> <html> <head> <title>Change Rank</title> <link rel="stylesheet" href="../includes/in.css" type="text/css"> <style type="text/css"> .infobg { font-family: Arial; font-weight:normal; font-size:12px; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; background: URL(textbg1.png); font-weight:300; } .button { font-size: 12px; background:url(button.png); vertical-align: middle; border-top: 1px solid #000000; border-right: 1px solid #000000; border-bottom: 1px solid #000000; border-left: 1px solid #000000; color: #FFFFCC; height:23px; font-weight:300; border-radius: 10px; padding-bottom:2px; } </style> </head> <body> <form action='' method='post' name='form1'> <table width='30%' cellpadding='0' align='center' cellspacing='0' border='1' bordercolor='#000000' bgcolor='#808080' style='border-collapse: collapse'> <tr> <td background='../header.jpg' colspan='2' align='center'>Change Rank</td> <tr> <td>Username:</td><td><input type='text' name='user'></td> </tr> <tr> <td>Rank:</td><td><input type='text' name='newrank'></td> </tr> <tr> <td> </td><td><input type="submit" name="update" value="Update Rank"></td> </tr> </form> </table> </body> </html> But there seems to be something wrong with that code, which I carnt see or work out. When I click Update submit button it does nothing, but can anyone see why it does nothing? Thanks. Ok I got this column "date_reg" on my table which has a "datetime" type. It's giving me a value like "2012-04-20 04:28:03" The problem is, when I'm trying to insert on that column using this format Code: [Select] <?php $datenow = date('m/d/Y h:i:s a', time()); ?> it's giving me a value of "0000-00-00 00:00:00" which is suppose to be the current date and time the user add on that table. Anyone knows how I can fix this? Hello, i am trying to create a simple funtion that i can all upon to "turn off a website" i am calling the function by <?php siteonline(n); ?> and the function is function siteonline($msg){ $offlinecheck = mysql_query("SELECT * FROM acp") or die(mysql_error()); $siteoffline = mysql_fetch_array($offlinecheck); $ifsiteoffline = $siteoffline['site_offline']; $offline = $siteoffline['offline_msg']; if ($ifsiteoffline == "y") { echo("$offline"); die();} } now this will turn off the site but it shows no message what so ever and i can not figure out why can anyone help? Cheers, Hi guys,
I am trying to echo multiple calendar events from a mysql table and order them by the date column.
There are several events on each day so I am trying to echo the date once then list the associated events under that date.
Such as
2014-05-10
Event 1, event 2, event 3
2014-05-11
Event 1, event 2, event 3
instead of
2014-05-10 event 1,
2014-05-10 event 2,
2014-05-10 event 3,
2014-05-11 event 1 etc...
This is my coding so far:
while($row = mysqli_fetch_assoc($result)) { $dutydate = $row['MyDate']; if($dutydate != $previousdate) { echo $dutydate.'<br />'; } elseif(!empty($dutydate)) { echo $dutydate.'<br />'; } echo $event1.' | '.$event2.' | '.$event3.'<br />'; $previousdate = $dutydate; } ?> Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\parkhall\quantities.php on line 21 This is the error message. This is the code. simple array query to display contents of table and I cant see where i have made the mistake. hopefully someone can help. <?php mysql_connect ("localhost", "******", "*****") or die ('I cannot connect to the database becuase: ' . mysql_error()); mysql_select_db ("matquant"); $query = mysql_query("SELECT * FROM quantities"); while ($row = mysql_fetch_array($query)) { //line referred to in error message echo "<br /> ID: " .$row ['id']. " material : " .$row ['material']. "quantity:" .$row['quantity']. "<br />";} ?> Please point out the probably glaring error. I'm relatively new to this and I am really not finding php easy to learn. Hi guys.I've got a problem.I'm building my php browsergame and i'm stuck into the inventory page.I have a code that seems ok to me but it won't work.Here it is: $inventory = array(); $query = sprintf("SELECT id, item_id, quantity FROM user_items WHERE user_id = '%s'", mysql_real_escape_string($userID)); $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $item_query = sprintf("SELECT name FROM items WHERE id = '%s'", mysql_real_escape_string($row['item_id'])); $item_result = mysql_query($item_query); list($row['name']) = mysql_fetch_row($item_result); array_push($inventory,$row); } I've spotted the problem.The $inventory array is empty.I checked it with if(empty($inventory)) .Thanks in advance and keep in mind that I'm a noob yet. Hi, This is a image tooltip from database. but I have got the problem, Not Working! How can i fix it. <a href="index.php?MD=urundetay&resimid=<?php echo $row_uruns['resimid']; ?>"><img src="urun_resim/<?php echo $row_image['image']; ?>" width="150" border="0" /></a> hello ! .. im a newi .. and i tried for a long time to fix this , its about comparison between the <form> information about the user and the actually information in the database ... LOGIN problem everytime he redirecty me to the main_page.php here is the proccesing code : <?php require_once("includes/connection.php");?> <?php require_once("includes/functions.php");?> <?php //to redirect u if u make an error ! global $errors; $errors=array(); $fields_array=array('user_name','user_password'); foreach($fields_array as $field){ if(!isset($_POST[$field]) || empty($_POST[$field])){ $errors[]=$field; }} if(!empty($errors)){ header("Location: errors.php"); exit; } ?> <?php $user_name=mysql_prep($_POST['user_name']); $user_password=mysql_prep($_POST['user_password']); ?> <?php $result=mysql_query("SELECT * FROM users",$connection); if(!$result){ die("Database query failed: " . mysql_error());} ?> <?php while($row=mysql_fetch_array($result)){ $user_ver=array($row['user_name'],$row['user_password']); if($user_ver[0]==$user_name AND $user_ver[1]==$user_password){ header("Location: login_suc.php"); exit; }} header("Location: main_page.php"); exit; ?> <?php mysql_close($connection); ?> |