-
Posts
142 -
Joined
-
Last visited
Never
About colleyboy
- Birthday 02/07/1988
Contact Methods
- MSN
-
Website URL
http://www.IRCDirect.co.uk
Profile Information
-
Gender
Male
-
Location
Essex, England
colleyboy's Achievements

Member (2/5)
0
Reputation
-
Calling database info from db with a LIKE query with a variable?
colleyboy replied to colleyboy's topic in PHP Coding Help
Ah-ha ... many thanks. It worked with '$letter%' Think this is calling the first letter now - I hope :S -
Calling database info from db with a LIKE query with a variable?
colleyboy replied to colleyboy's topic in PHP Coding Help
Basically I am trying to call back results which start with the letter. I tried removing the ; but has not worked . If I replace with 'A%' or 'B%' it works fine but cant seem to get it to work with a variable. -
I am trying to call results from a database where a letter is equal to a letter. I have already called the variable $letter; to look at the url and use this result at the variables contents. I.E: $letter = A I am trying to call via MYSQL any rows matching a certain letter. This letter is defined by $letter. I cant seem to put this in correctly? can anyone help? $query="SELECT * FROM products WHERE product_name LIKE '$letter;%' ORDER by variety ASC";
-
Skip the first line when processing CSV file.
colleyboy replied to colleyboy's topic in PHP Coding Help
That would be nice but if it is not real-time then just a way to display the output so all the columns of code are not together when it shows what it has put in the db. -
Skip the first line when processing CSV file.
colleyboy replied to colleyboy's topic in PHP Coding Help
Many Thanks. I have another question though? How would I display the results better on the page. At the moment it processes and displays it like: File dutchhouseproducts.csv uploaded successfully. Displaying contents: product_name,variety,description,price Red Flower,Roses,This is a description for the red flower,3.99 Yellow Flower,Roses,This is a lovely yellow flower,14.99 Import done I would like it to display a row at a time... Example: File dutchhouseproducts.csv uploaded successfully. Displaying contents: Row 1: Red Flower,Roses,This is a description for the red flower,3.99 Row2: Yellow Flower,Roses,This is a lovely yellow flower,14.99 Import Complete. -
Skip the first line when processing CSV file.
colleyboy replied to colleyboy's topic in PHP Coding Help
I thought logically to what you said and added it and it worked //Upload File if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>"; echo "<h2>Displaying contents:</h2>"; readfile($_FILES['filename']['tmp_name']); } //Import uploaded file to Database $handle = fopen($_FILES['filename']['tmp_name'], "r"); $data = fgetcsv($handle, 1000, ","); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT into products(product_name,variety,description,price) values('$data[0]','$data[1]','$data[2]','$data[3]')"; mysql_query($import) or die(mysql_error()); } fclose($handle); print "Import done"; "Eureka!" - Thanks -
Skip the first line when processing CSV file.
colleyboy replied to colleyboy's topic in PHP Coding Help
This is what I understand from the code: //Import uploaded file to Database $handle (variable for handling request to open CSV) = fopen($_FILES['filename']['tmp_name'] (opens the file from the temp directory), "r (retreives)"); (This is the loop part I think where it looks up the csv contents and fetches the data for the first 1000 rows of data) while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { (this bit imports the data into the database as per the column names in the database and the column count in the csv file) $import="INSERT into products(product_name,variety,description,price) values('$data[0]','$data[1]','$data[2]','$data[3]')"; (if there is an error importing stop) mysql_query($import) or die(mysql_error()); } (closes the csv opening session) fclose($handle); (echo's it has done) print "Import done"; This is what I understand from the code. Please let me know if I am thinking along the right lines? -
Skip the first line when processing CSV file.
colleyboy replied to colleyboy's topic in PHP Coding Help
Sorry I am a bit new to loops. I got this code elsewhere and have done little things to it but am stuck on this bit. Please can you help me out. Much appreciated -
Skip the first line when processing CSV file.
colleyboy replied to colleyboy's topic in PHP Coding Help
Do you mean like this? :S $handle = fopen($_FILES['filename']['tmp_name'], "r"); while (($data = fgetcsv($handle, 1000, ","($data = fgetcsv($handle, 1000, ","))) !== FALSE) { $import="INSERT into products(product_name,variety,description,price) values('$data[0]','$data[1]','$data[2]','$data[3]')"; mysql_query($import) or die(mysql_error()); } fclose($handle); -
Hi have found a great script to upload CSV files into a mysql database. Problem is that it uploads the first line of the file. I need it to skip this line as it only has headers for the columns. Is there any way to "skip this?" Upload.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=iso-8859-1" /> <title>Upload page</title> <style type="text/css"> body { background: #E3F4FC; font: normal 14px/30px Helvetica, Arial, sans-serif; color: #2b2b2b; } a { color:#898989; font-size:14px; font-weight:bold; text-decoration:none; } a:hover { color:#CC0033; } h1 { font: bold 14px Helvetica, Arial, sans-serif; color: #CC0033; } h2 { font: bold 14px Helvetica, Arial, sans-serif; color: #898989; } #container { background: #CCC; margin: 100px auto; width: 945px; } #form {padding: 20px 150px;} #form input {margin-bottom: 20px;} </style> </head> <body> <div id="container"> <div id="form"> <?php include "connection.php"; //Connect to Database $deleterecords = "TRUNCATE TABLE tablename"; //empty the table of its current records mysql_query($deleterecords); //Upload File if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "<h1>" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "</h1>"; echo "<h2>Displaying contents:</h2>"; readfile($_FILES['filename']['tmp_name']); } //Import uploaded file to Database $handle = fopen($_FILES['filename']['tmp_name'], "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $import="INSERT into products(product_name,variety,description,price) values('$data[0]','$data[1]','$data[2]','$data[3]')"; mysql_query($import) or die(mysql_error()); } fclose($handle); print "Import done"; //view upload form }else { print "Upload new csv by browsing to file and clicking on Upload<br />\n"; print "<form enctype='multipart/form-data' action='upload.php' method='post'>"; print "File name to import:<br />\n"; print "<input size='50' type='file' name='filename'><br />\n"; print "<input type='submit' name='submit' value='Upload'></form>"; } ?> </div> </div> </body> </html>
-
Hi, I am modifying a script which is a HTML5/Jquery drop down menu. I have done it all but cannot seem to center the menu images. Any idea what I need to edit? Nav.html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>HTML5, CSS3 and jQuery Navigation menu</title> <link rel="stylesheet" href="css/nav.css"> <!--[if IE]> <script src="scripts/html5.js"></script> <![endif]--> </head> <body class="no-js" topmargin="0" rightmargin="0" leftmargin="0"> <nav id="topNav"> <ul> <li><a href="#" title="Nav Link 1"><IMG SRC="images/homepagebutton.png"></a></li> <li> <a href="#" title="Nav Link 1"><IMG SRC="images/companybutton.png"></a> <ul> <li><a href="#" title="Sub Nav Link 1">Sub Nav Link 1</a></li> <li><a href="#" title="Sub Nav Link 2">Sub Nav Link 2</a></li> <li><a href="#" title="Sub Nav Link 3">Sub Nav Link 3</a></li> <li><a href="#" title="Sub Nav Link 4">Sub Nav Link 4</a></li> <li class="last"><a href="#" title="Sub Nav Link 5">Sub Nav Link 5</a></li> </ul> </li> <li><a href="#" title="Nav Link 1"><IMG SRC="images/productandservicesbutton.png"></a></li> <li><a href="#" title="Nav Link 1"><IMG SRC="images/qualitybutton.png"></a></li> <li><a href="#" title="Nav Link 1"><IMG SRC="images/worldwidelocationsbutton.png"></a> <ul> <li><a href="#" title="Sub Nav Link 1">England</a></li> <li><a href="#" title="Sub Nav Link 2">France</a></li> <li><a href="#" title="Sub Nav Link 3">Sweden</a></li> <li><a href="#" title="Sub Nav Link 4">Poland</a></li> <li class="last"><a href="#" title="Sub Nav Link 5">Sub Nav Link 5</a></li> </ul> </li> <li><a href="#" title="Nav Link 1"><IMG SRC="images/enquiriesbutton.png"></a></li> </ul> </nav> <script src="js/jquery.js"></script> <script src="js/modernizr.js"></script> </body> </html> nav.css: /* JS disabled styles */ .no-js nav li:hover ul { display:block;} /* base nav styles */ nav { display:block; margin:0 auto 0px; position:relative; background-image:url('../images/menubg.png'); font:16px Tahoma, Sans-serif; } nav ul { padding:0; margin:0; } nav li { position:relative; float:left; list-style-type:none;} nav ul:after { content:"."; display:block; height:0; clear:both; visibility:hidden; } nav li a { display:block; padding:0px 0px; border-right:1px dashed #222; color:#eee; text-decoration:none; height:35px; } nav li a:focus { outline:none; text-decoration:underline; } nav li:first-child a { border-left:none; } nav li.last a { border-right:none; } nav a span { display:block; float:right; margin-left:5px; } nav ul ul { display:none; width:100%; position:absolute; left:0; background:#6a6a6a; } nav ul ul li { float:none; } nav ul ul a { padding:5px 10px; border-left:none; border-right:none; font-size:14px; } nav ul ul a:hover { background-color:#555; } Another thing... it appears fine in Chrome but has a border around the dashed breakers inbetween the images in IE. Any ideas please as I am a bit lost. Kind Regards, Ian
-
No it is blank on the page source where it should say "like"
-
Tried an elseif statement too (!=) but still isnt showing the echo... hmm
-
Help with simple if statement and the use of && (AND)
colleyboy replied to colleyboy's topic in PHP Coding Help
No problem... fixed it now Thanks ! -
Hello, I have gave you an extended snippet of the code and removed the && as I see I reference it twice (good spot ). The <FONT> tags are temp until I sort the code then I will cleanup with some CSS . <!-- LIKE BUTTON --> <?php if (isset($_SESSION['useridkey'])){ //check user id in url matches useridkey if ($_SESSION['useridkey']==$the_user_id){ // the following if the session id matches the variable //edit profile page echo "sessionid matches the user id variable"; } $loggedinuserid = $_SESSION['useridkey']; // if they are logged in $aretheyliked = mysql_query("SELECT * FROM boom_likes WHERE user_id=$loggedinuserid"); while($row = mysql_fetch_array($aretheyliked)) { //if they are liked by the user if (($row['liked_user_id']==$profileuserid))){ echo "<FONT SIZE=1 COLOR=BLUE>You Like This Artist"; } else { echo "Like"; } } // end of if they are logged in } else { // if they are not logged in echo "<FONT SIZE=1 COLOR=RED>You must be logged in to like this artist"; } ?> <!-- END OF LIKE BUTTON -->