-
Posts
364 -
Joined
-
Last visited
-
Days Won
1
Everything posted by Love2c0de
-
Have you got an 'ID' field in your database table? Regards, Lab.
-
Yup cyberRobot I think has got your problem spot on. I just read your first post again and I think that's what you will want. Not sure why you have 2 forms, with the 2nd only containing hidden fields? You could just put your hidden fields within your a1 form so that you can retrieve the values on a server-side script(if that was the plan). I don't think you will be able to retrieve those hidden values from your a2 form. Kind regards, L2c.
-
I've coded in XHTML since 2010 and close all self-closing tags, like <br />, <hr />, <img />, <link />K Kind regards, L2c.
-
I do like this forum but an upgrade always sounds good. Regards L2c
-
No problem for the trouble, my FF keeps randomly crashing as of recent so I thought I'd go for the IE. Thanks for the replies, I actually just tried in IE10 to go to a new line, but using the full-text editor in plain mode and when I press enter, it does a space Regards, L2c.
-
So you want to show only 1 form and make the first form auto send? Regards, L2c.
-
Sounds like a freelancing post. To be fair that would be quite a task for even a good php programmer, it's not a run of the mill thing, quick thing to do. I'm sure what you are asking for is possible but I'm not sure how useful someone posting some code and leaving you to get on with it will be. Good luck though I hope you can get this sorted. FREE is always best! Kind regards, L2c.
-
Sorry, not when I try to post but when I try to go to a new line, it won't go. Regard, L2c. (in FF now)
-
Your posts have been invaluable to me. Thank you so much for taking the time to explain in great detail about my specific problem. Unfortunately I think I have stumbled upon a pretty bad problem with my site setup. I have 1 main index.php page where I load templates containing HTML into the specific areas. I have a backend php script which searches the directory and depending on the value of a $_GET variable, will load the specific page required. Here is that page: <?php session_start(); require("core/initialize.php"); if(!isset($_SESSION['username']) && $_GET['page'] == "home") { require("core/db_queries/main_query.php"); } if(isset($_POST['reg_username'])) { require('core/register.php'); } if(isset($_POST['login_username'])) { require('core/login.php'); } if(isset($_POST['demo_name'])) { require('core/upload.php'); } if(isset($_GET['page']) && $_GET['page'] == 'logout') { require('core/logout.php'); } if(isset($_SESSION['username'])) { $member_dashboard = "<div id='dashboard'>"; $member_dashboard .= "<span>Welcome, {$_SESSION['username']}</span>"; $member_dashboard .= "<a href='?page=profile'><img src='images/my_profile.jpg' alt='Profile' title='Profile' /><br />Profile</a>"; $member_dashboard .= "<a href='?page=upload'><img src='images/upload_icon.png' alt='Upload a Demo' title='Upload' /><br />Upload</a>"; $member_dashboard .= "<a href='?page=write_review'><img src='images/review_icon.jpg' alt='Write Review' title='Write Review' /><br />Write Review</a>"; $member_dashboard .= "<a href='?page=my_demos'><img src='images/disc_icon.jpg' alt='My Demos' title='My Demos' /><br />My Demos</a>"; $member_dashboard .= "</div>"; $nav_link = "<li><a href='?page=upload'>Upload A Demo</a></li><li><a href='?page=my_demos'>My Demos</a></li><li id='logout'><a href='?page=logout'>Logout</a></li>"; } else { $form = "<form name='quick_login' method='post' action='?page=home'>"; $form .= "<input type='text' placeholder='username...' name='login_username' />"; $form .= "<input type='password' placeholder='password...' name='login_password' />"; $form .= "<input type='submit' name='submit' value='Login' />"; $form .= "</form>"; $form .= "<a href='?page=register' class='form_links green'>Need to Register?</a>"; $form .= "<a href='?page=reset_pass' class='form_links red'>Forgot your login?</a>"; } include("core/sidebars.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Demo Central - <?php print($title); ?></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta name="description" content="Some description here." /> <script type="text/javascript" src="js/jquery-1.8.3.js"></script> <link rel="stylesheet" type="text/css" href="styles/gaming_styles.css" /> <script type="text/javascript"> $(function(){ $('#navigation li').hover(function(){ $(this).css("background-image","url('images/menu_hover.jpg')"); },function(){ $(this).css("background-image","url('images/background_img.jpg')"); }); }); </script> </head> <body> <div id="header"> <a href="?page=home"> <img src="images/gaming_logo.png" alt="Logo" title="Gaming Logo" id="logo" /> </a> <?php if(isset($quick_error)){print($quick_error);} if(isset($form)){print($form);}//contains the 2 links also if(isset($member_dashboard)){print($member_dashboard);} ?> </div> <ul id="navigation"> <!--list items must be on one line because browsers create space between links if they are each on a separate line.--> <li><a href="?page=home">Home</a></li><li><a href="?page=games">Games</a></li><li><a href="?page=reviews">Reviews</a></li><li><a href="?page=feedback">Feedback</a></li><li><a href="?page=contact">Contact</a></li><?php if(isset($nav_link)){print($nav_link);}?> </ul> <div id="content_wrapper"> <div id="left_container"> <?php if(isset($left_sidebar)){print($left_sidebar);} ?> </div> <div id="right_container"> <?php if(isset($right_sidebar)){print($right_sidebar);} ?> </div> <div id="container"> <?php include($output); ?> <?php if(isset($dynamic_home) && $_GET['page'] == "home"){print($dynamic_home);} ?> </div> </div> </body> </html> Now, as you can see, I execute this at the top of my page: if(!isset($_SESSION['username']) && $_GET['page'] == "home") { require("core/db_queries/main_query.php"); } The main_query.php is the file which I have been posting about all along. At the bottom of this script I have added this: $num_mem = $member[0][2]; $num_dem = $demo[0][6]; These values as you can guess return the total values of users and demorecs. BUT, I need to display this in the left navigation bar. I have a backend php script which sets up the data for the sidebars (left and right). This is included in my index.php page just before the HTML DOCTYPE (I put it here to make sure that $num_mem and $num_dem variables are set). They are set and they are printing out ok. Trouble is I want that information in the sidebars (site stats) to display ONLY if the user is not logged in, as soon as the session is set, I change the data to user-related information (or as is the plan). I have taken the "&& $_GET['page'] == 'home'" out of the if statement to execute the main_query.php as I want it to display this info on all pages except when the user logs in. I can get around this problem by leaving my print out code like this: <?php if(isset($dynamic_home) && $_GET['page'] == "home"){print($dynamic_home);} ?> But this is dirty as it will still do the queries but won't print the end result. This is obviously not my desired result. I know I can target if the user is logged in and what page they are on but it doesn't feel right. There must be a simpler way. Do I just add a new query to my sidebars.php script? It just all seems jumbled up at the moment, queries here and there. Would it be best to have one main query file containing many different queries within say a switch statement, which I just call when I need, passing in a value to the switch to select the correct query (and of course have the 'most used' queries in a certain block of code)? Getting in a muddle, I stayed up from 2am this morning and completed all this round early morning so I've not had much chance to take it in properly. I knew there was a problem this morning and it's been on my mind. Do you have any thoughts for me or opinions? Kind regards, L2c.
-
Everytime I try to post using IE10 browser the return (enter) key doesn't seem to work. Anyone else had this problem? As you can see! :# Kind regards, L2c. Happens on another forum which uses the same type of forum also.
-
Welcome to the forums Regard,Lc.
-
I wanted to count the full total of users which re registered but my query limits it to return only 5 rows, so I need a way to count the total number of rows in the database. That's a very good point, I'll process the data within the while when I retrieve the information from the database. I'm literally running the code on my localhost, although I do get a configure error message everytime I load up phpMyAdmin. Kind regards, L2c.
-
Edit: It's not overwriting my username field. I am getting the correct data but my only issue now is that my for loop only seems to be printing out once and then exiting. Edit: Seems that the query is only returning 1 row of data. I execute a print_r on the $member array just after fetching the data in the while loop and it's printing out only the first row of data. Sorry, Regards, L2c.
-
Thank you for your detailed response. I will keep re-reading this thread, I decided to go with your code as it made much more sense, minimized the code written and is generally more readable. I have carried on and created a news table and added content to be displayed. Trouble with this now is I have 3 queries on the page and I am beginning to notice this on page load. My updated code is here: <?php //general database information - latest members, latest demo's uploaded, $headings = array("Latest 5 Members","Lastest 5 Demos"); $member = array(); $demo = array(); $path = "core/demos/"; $dynamic_home = ""; $c = 0; $i = 0; $con = mysqli_connect("localhost", "root", "", "gaming") or die("Error connecting to the server."); $sql = 'SELECT username, DATE_FORMAT(join_date, "%d/%m/%y") AS join_date_str FROM users ORDER BY join_date DESC LIMIT 5'; $qry = mysqli_query($con, $sql); while ($row = mysqli_fetch_row($qry)) { $member[] = $row; } $sql = 'SELECT game_id, file_name, demo_name, demo_desc, uploaded_by, DATE_FORMAT(upload_date, "%d/%m/%y") AS upload_date_str FROM demos ORDER BY upload_date DESC LIMIT 5'; $qry = mysqli_query($con, $sql); while ($row = mysqli_fetch_row($qry)) { $demo[] = $row; } $lengths = count($member); $mem_len = count($member[0]); $dem_len = count($demo[0]); $dynamic_home = "<h4 class='stat_head'>{$headings[0]}</h4>"; $dynamic_home .= "<table id='table1'>"; $dynamic_home .= "<tr>"; $dynamic_home .= "<th>Username</th>"; $dynamic_home .= "<th>Join Date</th>"; $dynamic_home .= "</tr>"; for ($i; $i < $lengths; $i++) { $dynamic_home .= "<tr>"; for ($c; $c < $mem_len; $c++) { $dynamic_home .= "<td>{$member[$i][$c]}</td>"; } $dynamic_home .= "</tr>"; $c = 0; } $c = 0; $i = 0; $dynamic_home .= "</table>"; $dynamic_home .= "<h4 class='stat_head'>{$headings[1]}</h4>"; $dynamic_home .= "<table id='table2'>"; $dynamic_home .= "<tr>"; $dynamic_home .= "<th>Game</th>"; $dynamic_home .= "<th>Demo Name</th>"; $dynamic_home .= "<th>Title</th>"; $dynamic_home .= "<th>Description</th>"; $dynamic_home .= "<th>Uploaded By</th>"; $dynamic_home .= "<th>Upload Date</th>"; $dynamic_home .= "</tr>"; for ($i; $i < $lengths; $i++) { $dynamic_home .= "<tr>"; for ($c; $c < $dem_len; $c++) { if ($c == 1) { $dynamic_home .= "<td><a href='{$path}{$demo[$i][$c]}'>{$demo[$i][$c]}</a></td>"; } else { $dynamic_home .= "<td>{$demo[$i][$c]}</td>"; } } $dynamic_home .= "</tr>"; $c = 0; } $dynamic_home .= "</table>"; $dynamic_home .= "<h4 class='stat_head'>News & Updates</h4>"; $dynamic_home .= "<div id='news_div'>"; $sql = 'SELECT id, news_title, news_desc, DATE_FORMAT(news_date, "%W %D %M %x") AS news_date_str FROM news ORDER BY news_date ASC LIMIT 5'; $qry = mysqli_query($con, $sql); while ($row = mysqli_fetch_assoc($qry)) { $dynamic_home .= "<h4 class='news_title'>{$row['news_title']} - <span class='news_date'>{$row['news_date_str']}</span></h4>"; $dynamic_home .= "<p class='news_desc'>{$row['news_desc']}</p>"; } $dynamic_home .= "</div>"; mysqli_close($con); ?> I am trying to count the number of rows in the users table so that I can display some statistics in a sidebar. I've tried adding the mysql COUNT() function into my 'users' select query, but it seems to overwrite my username field and it only prints one row of data. It is printing the correct number of rows but seems to be breaking my query. How can I count the number of rows within that query? I would rather grab that number now while I am querying that table rather than having to do another query just to count the number of rows. Thanks once again much appreciated. Kind regards, L2c.
-
Hi David, Thank you very much for your reply, I knew there would be major flaws in my work but I couldn't see them at all. Your post was eye opening to say the least. I will get to work on this now. I'll let you know how I get on! Is it really necessary for the 2 queries though? I was told I should try to limit 1 query to each page if possible. I thought the reason of a join was to prevent having to run 2 queries to grab data from separate tables. Was it my 'WHERE user.id = demos.gid' part which was causing most of the duplicate issues? The reason I added the WHERE clause is because when I ran the query without it, it would first iterate through the demos table 'g_id' 5 times, then iterate through the users 'id', giving me duplicated data as it was printing the same id, username and join_date for every demo, then it would iterate to the second id in the users table and re-print the 5 demos again but with the same username etc. Love the way you have formatted the date within the query string as well, I had issues with the dates being returned as strings, even though they were stored within an 'int' table field at one point and this method of doing it prevents me from having to work with the multi-dim array, sending it all to a standard level array. When printing the data, I just need to limit the amount of data printed in each row to the required number, for example I can limit the $member iteration to 3 seeing as though I need only the id, username and join date. So after every 3 iterations, I print a new table row. Thanks again David, Kind regards, L2c.
-
Sorted it. Her is the updated code: <?php //general database information - latest members, latest demo's uploaded, $con = mysqli_connect("localhost", "root", "", "gaming") or die("Error connecting to the server."); $qry = mysqli_query($con,"SELECT users.id,users.username,users.join_date, demos.gid,demos.game_id,demos.file_name, demos.demo_name,demos.demo_desc, demos.uploaded_by,demos.upload_date FROM users, demos WHERE users.id = demos.gid") or die("Error selecting data."); $headings = array("Latest 5 Members","Lastest 5 Demos Uploaded"); $member = array(); $demo = array(); $mem_out = ""; $dem_out = ""; $c = 0; $n = 0; $i = 0; while ($row = mysqli_fetch_row($qry)) { while($c < 3) { $member[$n][$c] = $row[$c]; if ($c == 2) { $member[$n][$c] = date("d/m/y", strtotime($member[$n][$c])); } $c++; } while($c < 10) { $demo[$n][$i] = $row[$c]; if ($i == 6) { $demo[$n][$i] = date("d/m/y", strtotime($demo[$n][$i])); } $c++; $i++; } $c = 0; $i = 0; $n++; } /* echo "<pre>"; print_r($member); echo "</pre>"; echo "<pre>"; print_r($demo); echo "</pre>"; */ $lengths = count($member); $mem_len = count($member[0]); $dem_len = count($demo[0]); $mem_out = "<table>"; $mem_out .= "<tr>"; $mem_out .= "<th>No.</th>"; $mem_out .= "<th>Username</th>"; $mem_out .= "<th>Join Date</th>"; $mem_out .= "</tr>"; for ($i; $i < $lengths; $i++) { $mem_out .= "<tr>"; for ($c; $c < $mem_len; $c++) { $mem_out .= "<td>{$member[$i][$c]}</td>"; } $mem_out .= "</tr>"; $c = 0; } $i = 0; $c = 1; $mem_out .= "</table>"; $dem_out = "<table>"; $dem_out .= "<tr>"; $dem_out .= "<th>Game</th>"; $dem_out .= "<th>Demo Name</th>"; $dem_out .= "<th>Title</th>"; $dem_out .= "<th>Description</th>"; $dem_out .= "<th>Uploaded By</th>"; $dem_out .= "<th>Upload Date</th>"; $dem_out .= "</tr>"; for ($i; $i < $lengths; $i++) { $dem_out .= "<tr>"; for ($c; $c < $dem_len; $c++) { $dem_out .= "<td>{$demo[$i][$c]}</td>"; } $dem_out .= "</tr>"; $c = 1; } $dem_out .= "</table>"; ?> To be honest I don't like it, feels like a bad approach but it's working so now I'll try to improve the code because I know it definitely can be somehow.. Kind regards,
-
Good morning all, I have been working on a website which allows users to register and upload files. I have 3 tables currently -> 'users', 'demos' and 'games'. I am trying to retrieve user information, and uploaded files information from the 2 tables. I use a select query to grab the information from both tables. The aim is to display the latest 5 registered users and the latest 5 uploaded files on the homepage. Here is my code so far: <?php //general database information - latest members, latest demo's uploaded, $con = mysqli_connect("localhost", "root", "", "gaming") or die("Error connecting to the server."); $qry = mysqli_query($con,"SELECT users.id,users.username,users.join_date, demos.gid,demos.game_id,demos.file_name, demos.demo_name,demos.demo_desc, demos.uploaded_by,demos.upload_date FROM users, demos WHERE users.id = demos.gid") or die("Error selecting data."); $headings = array("Latest 5 Members","Lastest 5 Demos Uploaded"); $member = array(); $demo = array(); $c = 0; $n = 0; $i = 0; while ($row = mysqli_fetch_row($qry)) { while($c < 3) { $member[$n][$c] = $row[$c]; if ($c == 2) { $member[$n][$c] = date("d/m/Y", strtotime($member[$n][$c])); } $c++; } while($c < 10) { $demo[$n][$i] = $row[$c]; if ($i == 6) { $demo[$n][$i] = date("d/m/Y", strtotime($demo[$n][$i])); } $c++; $i++; } $c = 0; $i = 0; $n++; } echo "<pre>"; print_r($member); echo "</pre>"; echo "<pre>"; print_r($demo); echo "</pre>"; ?> This is working fine and is creating 2 multi-dimensional arrays, splitting the specific information into the correct array. The first inner while loop put's user information to the $member array. The second inner while loop puts demorec information into the $demos array by looping through the rest of the $row, carrying on the incrementing from the first inner while. I am seeking advice on a number of things: Is my code for separating the data suitable or is it overkill? Is there an easier way to do this? As you can see 3 while loops seems a bit OTT to me but I'm not sure, it was the only way I could get it to work. I re-wrote what I'd previously done numerous times. About the query, I need to still put a LIMIT but I just wanted to get the data sorted first. Are there particular functions I wuld find useful for working with multi-dimensional arrays? I've looked at php.net and other places but it seems I would use something similar to my code above, but rather than storing the data-set it up for being printed Thank you for any replies and help. Regard, L2c.
-
Congrats Christian! Regards, L2c.
-
Fair enough, thank you for clarifying that. Kind regards, L2c.
-
Do I have to hardcode the spaces for example Deus%20Ex when passing the value through the URL? My colons appear to encode in the URL bar when using urlencode() but the spaces don't. I've seen on websites where you see the url encoded in the url bar and not just the source. Is there some kind of directive I need to change in php.ini? I've tried urlencode too but doesn't seem to encode anything but colons. Sorry disregard that whole post^^ Regards, L2c.
-
Try adding this: background-size: cover; Regards, L2c.
-
Just changed it to mysqli_fetch_assoc and I'm getting exactly what I want. Thanks very much! Regards, L2c.