
mdemetri2
Members-
Posts
79 -
Joined
-
Last visited
Everything posted by mdemetri2
-
erm, $num++; ?? And by comparing what I have and what you sent I also realised that I am not using what you provided.....probably because I failed miserably to implement it the first time round, and then got changing it using other reponses or things I found! It's been one of those days....I will try yours again.
-
Thanks to both of you. Ok, so I moved the style section to after the title section. Jessica, you said I need to increment the counter but I am really not sure what to change and therefore how to do this.....I assume something like $count + 1 somewhere? I really do need to find out how to understand your code and break it down into what each part is doing.... <table width="600" border="0"> <tr> <td>User</td> </tr> <?php $count = 0; do { ?> <tr> <td class="<?php echo (($count % 2) == 0) ? 'even' : 'odd'; ?>"><?php echo $row_recordset1['userid']; ?></td> </tr> <?php } while ($row_recordset1 = mysql_fetch_assoc($recordset1)); ?> </table>
-
many thanks for the reply and help Eiseth, I now have the following code: <?php require_once('Connections/Connection1.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_Connection1, $Connection1); $query_recordset1 = "select * from users"; $recordset1 = mysql_query($query_recordset1, $Connection1) or die(mysql_error()); $row_recordset1 = mysql_fetch_assoc($recordset1); $totalRows_recordset1 = mysql_num_rows($recordset1); ?> <style type="text/css"> .odd { background-color: blue; } .even { background-color: white; } </style> <html> <head> <title>How To Create Zebra Striped Table</title> </head> <body> <table width="600" border="0"> <tr> <td>User</td> </tr> <?php $count = 0; do { ?> <tr> <td class="<?php echo (($count % 2) == 0) ? 'even' : 'odd'; ?>"><?php echo $row_recordset1['userid']; ?></td> </tr> <?php } while ($row_recordset1 = mysql_fetch_assoc($recordset1)); ?> </table> </body> </html> <?php mysql_free_result($recordset1); ?> and it still isn't working. As you can tell I'm poking around in the dark here being new to this somewhat!
-
Ok, I have gone back to a simple table, that is populated by a query. Jessica - please would you be able to provide some pointers on where I need to adapt your example to make the following alternate the colour on the rows: <?php require_once('Connections/Connection1.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_Connection1, $Connection1); $query_recordset1 = "select * from users"; $recordset1 = mysql_query($query_recordset1, $Connection1) or die(mysql_error()); $row_recordset1 = mysql_fetch_assoc($recordset1); $totalRows_recordset1 = mysql_num_rows($recordset1); ?> <style type="text/css"> .odd { background-color: blue; } .even { background-color: white; } </style> <html> <head> <title>How To Create Zebra Striped Table</title> </head> <body> <table width="600" border="0"> <tr> <td>User</td> </tr> <?php do { ?> <tr> <td><?php echo $row_recordset1['userid']; ?></td> </tr> <?php } while ($row_recordset1 = mysql_fetch_assoc($recordset1)); ?> </table> </body> </html> <?php mysql_free_result($recordset1); ?>
-
Ok, it seems I chose a poor example from my google search results, apologies. So, can I use your example instead, remove my use of .tableClass and keep the .odd and .even ones? Also, do I replace Row Data Here with echo $row_recordset1['userid'];
-
Thanks for the reply Jessica. This is the latest bit of code I have been playing with that was supposed to work in IE8...: <?php require_once('Connections/Connection1.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_Connection1, $Connection1); $query_recordset1 = "select * from users"; $recordset1 = mysql_query($query_recordset1, $Connection1) or die(mysql_error()); $row_recordset1 = mysql_fetch_assoc($recordset1); $totalRows_recordset1 = mysql_num_rows($recordset1); ?> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script><script type="text/javascript"> $(function() { // $('.tableClass tr:even').addClass('even'); $('.tableClass tr:odd').addClass('odd'); }); </script> <style type="text/css"> .tableClass{ } .odd { background-color: blue; } .even { background-color: white; } </style> <html> <head> <title>How To Create Zebra Striped Table</title> </head> <body> <table width="600" border="0"> <tr> <td> </td> </tr> <?php do { ?> <tr> <td><span class="tableClass"> <?php echo $row_recordset1['userid']; ?></span></td> </tr> <?php } while ($row_recordset1 = mysql_fetch_assoc($recordset1)); ?> </table> <p class="tableClass"> </p> </body> </html> <?php mysql_free_result($recordset1); ?> any ideas where it is wrong? this isnt actually working in chrome either....
-
Ok, so I have been able to get 'zebra striped' rows workin in google chrome, but uses CSS3 which isnt supported in ie8. Is there a method that works in IE8?
-
Hi, anyone got any ideas on this? Thanks
-
Thanks for the reply Muddy_Funster, I have adopted this code that currently allows me to login to my site, view main page that only has some text at the moment and welcome 'username', logout, and show an incorrect login attempt. Do I add what you suggest somewhere near the bottom by the headers as an and after the username and password has been checked..... <?php require_once('Connections/Connection1.php'); ?> <?php $tbl_name="users"; // Table name mysql_select_db($database_Connection1, $Connection1); // username and password sent from form $myusername=$_POST['myusername']; $mypassword=md5($_POST['mypassword']); // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE userid='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" session_register("myusername"); session_register("mypassword"); header("location:main.php?myusername=".$myusername); } else { header("location:login_failed.php"); //echo "Wrong Username or Password"; } ?> Thanks muchly!!
-
Hello Had some great help on here, and wondered if someone could help here too. If after has entered login details, and successfully got to the main page, is it possible to add in a function to check the user type and redirect to specific page? I have tried to find some working examples but most of these are members / non member based and I might want 3 or 4 types of user, so different start pages for each after a successful login....... Much appreciated!!
-
Hi thanks for the reply.....how do I implement that, and make it use my variable that holds the sql code form the previous page? Also, I am certain the problems that I have been having is because this is running from HTTPS......
-
Hi, so I have had some help on an other post creating a csv file from a query populating a html table on screen. The query is passed to a csv file creator, I adapted the code, but when it comes to download IE explorer complains it can't find the file or in it's current form below, opens the file as HTML and displays the data in the browser. Works find in Google Chrome, just not in IE8. Any ideas, I think it is to do with the headers and their order / content: <?php require_once('Connections/Connection1.php'); ?> <?php //create query to select as data from your table $select = $_GET['sqlcode']; $dbtable = "download"; //run mysql query and then count number of fields $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) ); $fields = mysql_num_fields ( $export ); //create csv header row, to contain table headers //with database field names for ( $i = 0; $i < $fields; $i++ ) { $header .= mysql_field_name( $export , $i ) . ","; } //this is where most of the work is done. //Loop through the query results, and create //a row for each while( $row = mysql_fetch_row( $export ) ) { $line = ''; //for each field in the row foreach( $row as $value ) { //if null, create blank field if ( ( !isset( $value ) ) || ( $value == "" ) ){ $value = ","; } //else, assign field value to our data else { $value = str_replace( '"' , '""' , $value ); $value = '"' . $value . '"' . ","; } //add this field value to our row $line .= $value; } //trim whitespace from each row $data .= trim( $line ) . "\n"; } //remove all carriage returns from the data //$data = str_replace( '\r' , " " , $data ); $data = str_replace( "\r\n", "", $data); //create a file and send to browser for user to download //header("Pragma: public"); //header("Expires: 0"); //header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //header("Cache-Control: private",false); //header('Content-Disposition: attachment; filename=customreport.csv'); //header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment;filename=export_".$dbtable.".csv "); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); //header("Content-Type: application/download"); header("Content-Transfer-Encoding: binary "); print "$header\n$data"; exit; ?>
-
Ok, I have adapted an other piece of code I came across: <?php require_once('Connections/Connection1.php'); ?> <?php //create query to select as data from your table $select = $_GET['sqlcode']; $dbtable = "download"; //run mysql query and then count number of fields $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) ); $fields = mysql_num_fields ( $export ); //create csv header row, to contain table headers //with database field names for ( $i = 0; $i < $fields; $i++ ) { $header .= mysql_field_name( $export , $i ) . ","; } //this is where most of the work is done. //Loop through the query results, and create //a row for each while( $row = mysql_fetch_row( $export ) ) { $line = ''; //for each field in the row foreach( $row as $value ) { //if null, create blank field if ( ( !isset( $value ) ) || ( $value == "" ) ){ $value = ","; } //else, assign field value to our data else { $value = str_replace( '"' , '""' , $value ); $value = '"' . $value . '"' . ","; } //add this field value to our row $line .= $value; } //trim whitespace from each row $data .= trim( $line ) . "\n"; } //remove all carriage returns from the data //$data = str_replace( '\r' , " " , $data ); $data = str_replace( "\r\n", "", $data); //create a file and send to browser for user to download //header("Pragma: public"); //header("Expires: 0"); //header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //header("Cache-Control: private",false); //header('Content-Disposition: attachment; filename=customreport.csv'); //header("Content-Type: application/octet-stream"); //header("Content-Transfer-Encoding: binary"); header("Content-Disposition: attachment;filename=export_".$dbtable.".csv "); header("Content-Type: application/force-download"); //header("Pragma: public"); //header("Expires: 0"); //header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/octet-stream"); //header("Content-Type: application/download"); //this line is important its makes the file name header("Content-Transfer-Encoding: binary "); print "$header\n$data"; exit; ?> The above code has a load of commented out header lines, this is where things are going wrong. As it is above, the file opens as HTML and displays all the text in the browser window. If I change the headers i.e. remove the comments and order, explorer complains that it can't find the file! Any help would be appreciated
-
hi, I thought I had cracked this, but it seems although it works, with certain larger numbers of rows returned in no longer pops up to save/open as a csv but in fact a html file....which does incidently then display all the records returned. I just wonder whether there is something in the content of the data that makes it act differently? Any ideas? This is the previously 'solved' code: <?php // // sample usage // $mysqli = new mysqli('xx.xxx.xx.xxx','xxxxxx','xxxxxxx','xxxxxxx'); $sql_query = $_GET['sqlcode']; sql2csv ($mysqli, $sql_query, 'employees.csv', 1); // // CSV download function // function sql2csv($mysqli, $sql, $filename='', $headings=1) { if (!$filename) $f = 'download_' . date('ymdhi') . '.csv'; else $f = $filename; $fp = fopen('php://output', 'w'); // so you can fputcsv to STDOUT if ($fp) { $res = $mysqli->query($sql); if ($res) { header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/octet-stream"); header('Content-Disposition: attachment; filename="'.$f.'"'); header("Content-Transfer-Encoding: binary"); $row = $res->fetch_assoc(); if ($headings) { fputcsv($fp, array_keys($row)); } do { fputcsv($fp, $row); } while ($row = $res->fetch_assoc()); } else echo "Error in query"; fclose($fp); exit; } }
-
PHP and MySQL Graphing options? Recommendations....
mdemetri2 replied to mdemetri2's topic in PHP Coding Help
Ok, I will do that and take a look at the tutorial. As always appreciate the offer to help. Leave it with me a few days. Have a good day! -
PHP and MySQL Graphing options? Recommendations....
mdemetri2 replied to mdemetri2's topic in PHP Coding Help
hmmm, ok taken a look at these. I think I'm leaning towards potentially using baaChart....but I have no clue how to configure it....so if I have a set data from a query (recordset in dreamweaver) how do I implement this being plotted? sorry, fairly new to all this I don't quite get the use of classes...... -
PHP and MySQL Graphing options? Recommendations....
mdemetri2 replied to mdemetri2's topic in PHP Coding Help
thanks for all your replies guys, appreciated once again. I will take a look...at these and see where I get to. -
Ok, came across, this and added it in. Seems IE8 needs more header detail.... header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); header("Content-Type: application/octet-stream"); header('Content-Disposition: attachment; filename="'.$f.'"'); header("Content-Transfer-Encoding: binary"); It works now, excellent, really appreciate the help!! Thank you.
-
ahaaa, I just tried this in Chrome and it worked!! Doesn't seem to like IE 8......any ideas?
-
thanks for the reply denno020, seems Barand uses fputcsv() in his method. Barand - I tried to use what you provided. I added in my connection details (in this format (also tried " around the variables: $mysqli = new mysqli('xx.xxx.xx.xxx','username','password','databasename'). I get the security bar in IE, then click download, but end up with: Internet Explorer cannot download. Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later. So your adopted code looks like: <?php // // sample usage // $mysqli = new mysqli('xx.xxx.xx.xxx','username','password','databasename'); $sql_query = $_GET['sqlcode']; (I tried adding in a simple query here too but it didn't make a difference) sql2csv ($mysqli, $sql_query, 'employees.csv', 1); // // CSV download function // function sql2csv($mysqli, $sql, $filename='', $headings=1) { if (!$filename) $f = 'download_' . date('ymdhi') . '.csv'; else $f = $filename; $fp = fopen('php://output', 'w'); // so you can fputcsv to STDOUT if ($fp) { $res = $mysqli->query($sql); if ($res) { header('Content-Type: text/csv'); header('Content-Disposition: attachment; filename="'.$f.'"'); header('Pragma: no-cache'); header('Expires: 0'); $row = $res->fetch_assoc(); if ($headings) { fputcsv($fp, array_keys($row)); } do { fputcsv($fp, $row); } while ($row = $res->fetch_assoc()); } else echo "Error in query"; fclose($fp); exit; } }
-
Any help appreciated here! hi, i came across an old thread that referred to some code which exports results of a query to a .csv file. However, it doesn't seem to create the file correctly, if you open the file the data doesn't display correctly, if you save it and change the file extension to .csv it opens as it should. I think there is a problem with the creation of the file portion of this code: <?php require_once('Connections/Connection1.php'); ?> <?php //create query to select as data from your table $select = $_GET['sqlcode']; //run mysql query and then count number of fields $export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) ); $fields = mysql_num_fields ( $export ); //create csv header row, to contain table headers //with database field names for ( $i = 0; $i < $fields; $i++ ) { $header .= mysql_field_name( $export , $i ) . ","; } //this is where most of the work is done. //Loop through the query results, and create //a row for each while( $row = mysql_fetch_row( $export ) ) { $line = ''; //for each field in the row foreach( $row as $value ) { //if null, create blank field if ( ( !isset( $value ) ) || ( $value == "" ) ){ $value = ","; } //else, assign field value to our data else { $value = str_replace( '"' , '""' , $value ); $value = '"' . $value . '"' . ","; } //add this field value to our row $line .= $value; } //trim whitespace from each row $data .= trim( $line ) . "\n"; } //remove all carriage returns from the data $data = str_replace( "\r" , "" , $data ); //create a file and send to browser for user to download header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$file_name.".csv"); print "$header\n$data"; exit; ?>
-
Hi, I have tried a few times to look into something that will allow me to pull data from mysql database to produce charts on a site that is currently coded in PHP, but quickly loose the plot when I come across the need to install library's on the server running the site - which I have access to but would need step by step instructions on what to do. Also, I have looked into some dreamweaver plugins but not quite done what I needed. So, can anyone recommend something that is fairly straightforward to implement and then configure to create the charts?? Many thanks Demetri
-
PHP / Dreamweaver and Creating User Restrictions
mdemetri2 replied to mdemetri2's topic in PHP Coding Help
Ok thanks trq, I did do a few searches, but didn't really come up with much. Plus I wasn't sure if it was fully code based or whether there was some dreamweaver configuration to make it happen.....or even a third party addon. I will take a look futher. Thanks. -
Hi All Wondering if anyone can point me in the right direction here. I have a site that is coded in PHP, with a mysql database attached. Currently I have users logging in, that quickly ended up with some functionality requiring splitting to certain users. Now I have read in dreamweaver you can restrict pages (not looked at it yet), but I wanted to check what method should be used to not only restrict pages but the content of pages? Currently I have had to create sub sites and specific login pages to achieve this. So as an example, if user A logs in, he get access to links 1, 2 and 3. If user B logs in though they should get links 1 and 3 only.... Any help and much appreciated.
-
deoiub, you assumptions are correct, smart. the download to excel creates: url.com/dl2excelscriptpage.php?sqlcode=SELECT blah blah blah......... the link echos the query submitted when the user submits their search, the page that creates the excel files takes the sqlcode variable passed in the url to sumbit the query and generate excel file from the results. this as I say fails when the sql is too long for the url so what you are saying is replicate the search from but so that it submits to the page which does the download to excel......I understand, I just need to spend some time on this! thank you ever so much for your help!