-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
mysql_query mysql_fetch_assoc mysql_fetch_row or, better, use the mysqli_ versions as mysql_ functions are deprecated
-
GROUP BY school_barcode, type_content
-
With PHP version < 5.4, the following willl work only if short_tags are enabled. <input type="text" name="name" value="<?=$name?>" /> if short_tags as disabled in the php.ini file you need to use <input type="text" name="name" value="<?php echo $name?>" /> Version >= 5.4 - this will work regardless of short_tag setting <input type="text" name="name" value="<?=$name?>" /> There should be no need for you to use eval() at all.
-
In a previous post you gave your column names as so in your last example above you need to reference $row['std_cell'] and not $row['stdcell']. The $row array indices will be the same as the column names. Similarly, in your second code, you need $class['class_id'] and $class['class_name']
-
try this method $adate = new DateTime('2013-10-20'); $bdate = new DateTime('2013-11-01'); $now = new DateTime(); $period = new DatePeriod($adate, new DateInterval('P1D'), $bdate); printf("%-15s\t%s\n", 'Date', 'Days elapsed'); foreach ($period as $dt) { printf("%-15s\t%6d\n", $dt->format('d M Y'), $dt->diff($now)->days); } /* RESULTS *************************************** Date Days elapsed 20 Oct 2013 26 21 Oct 2013 25 22 Oct 2013 24 23 Oct 2013 23 24 Oct 2013 22 25 Oct 2013 21 26 Oct 2013 20 27 Oct 2013 19 28 Oct 2013 18 29 Oct 2013 17 30 Oct 2013 16 31 Oct 2013 15 *****************************************************/
-
Then you have four options at least: Use a MySQL TIMESTAMP type column which will automatically set to current date on INSERT and optionally on UPDATE Use a DATE type column and place CURDATE() into the column on INSERT USE a DATETIME column and place NOW() into the column on INSERT Use PHP to get current date and place that in the date column
-
+--------------+ +-------------------+ | class | | student | +--------------+ +-------------------+ | class_id (PK)|--+ | serial number (PK)| | class_name | | | std_name | | date_created | | | std_father_name | +--------------+ | | std_roll_num | +---<| std_class (FK)| | std_cell | | std_address | | std_dob | | std_fee | +-------------------+ The primary keys are the unique identifiers of each record. Assuming std_class contains the id of the student's class then that would be a foreign key. To query the table using a JOIN you would have a query like this SELECT c.class_name, s.std_name, s.std_father_name FROM student as s INNER JOIN class as c ON s.std_class = c.class_id ORDER BY c.class_name Note that you need InnoDB tables to define foreign key constraints. You do not have to formally define a foreign key to use a field in a join.
-
there is an example here http://forums.phpfreaks.com/topic/282860-selectingsearching-rows-of-a-table-based-on-the-value-of-a-field-in-the-table/?do=findComment&comment=1453412
-
Check to see what mysql_error() contains after mysql_query(). Also echo $sql to see the query that is being executed
-
Are the ids numeric in all cases?
-
You seem to be over-complicating $in = 'test1.txt'; $out = 'test2.txt'; /******** * obfuscate */ $txt = file_get_contents($in); $str = ''; for ($i=0, $k=strlen($txt); $i<$k; $i++) { $str .= ~$txt[$i]; } file_put_contents($out, $str); /******* * output obfuscated text */ echo '<pre><hr>'; readfile($out); /******* * output deobfuscated text */ echo '<hr>'; $txt = file_get_contents($out); for ($i=0, $k=strlen($txt); $i<$k; $i++) { echo ~$txt[$i]; } echo '</pre>';
-
Numerous addition and subtraction elements in one query
Barand replied to Steve_NI's topic in MySQL Help
number_format in the PHP or use ROUND() in the query SELECT ROUND(SUM(....), 2) as total -
Numerous addition and subtraction elements in one query
Barand replied to Steve_NI's topic in MySQL Help
Don't leave a space between the SUM and the ( ie SUM( and not SUM ( Another solution would be SELECT SUM(total) FROM ( SELECT SUM(balance) as total FROM account UNION SELECT SUM(-balance) as total FROM credit_card UNION SELECT SUM(-amount) as total FROM bills WHERE date > 12 ) as tots -
It's certainly the easiest way to get the total of the values in an array
- 5 replies
-
- phpradio buttons
- form
-
(and 1 more)
Tagged with:
-
Mysql Query taking too much time. Almost 10 minutes
Barand replied to boomarang's topic in MySQL Help
The first thing to say is don't run queries inside loops - extremely inefficient. Run a single query with a JOIN. The second is don't use SELECT *. Specify the individual column that you want to retrieve. The query time is proportional to the amount of data retrieved so only get what you need. It seems you are only really interested in data from table2 (I have to use * as I don't know your columns) $sql = "SELECT t2.* FROM table1 t1 INNER JOIN table2 t2 ON t1.id = t2.tab_id WHERE t1.type = 'med' AND t1.submission_type = 'submission'"; $query = mysql_query($sql); while ($row = mysql_fetch_assoc($query)) { $valueArr[] = $row; } -
Set the values of the radio buttons to 1 - 5. Then $_POST['answer'] will contain the number of the button selected
- 5 replies
-
- phpradio buttons
- form
-
(and 1 more)
Tagged with:
-
Code not recognising opendir, readdir, feof, fgets?
Barand replied to dudebrodude's topic in PHP Coding Help
Are you sure the path "files" is correct? -
Code not recognising opendir, readdir, feof, fgets?
Barand replied to dudebrodude's topic in PHP Coding Help
No, it isn't. It is supposed to use readdir() to get the filenames which you then have to open then read. As I said -
Code not recognising opendir, readdir, feof, fgets?
Barand replied to dudebrodude's topic in PHP Coding Help
The point is you have not used fopen on the file before using feof() or fgets() -
What have you got so far?
-
Code not recognising opendir, readdir, feof, fgets?
Barand replied to dudebrodude's topic in PHP Coding Help
try if it recognizes fopen before trying to read from a file -
Dropdown menu will not output pm only am values to table
Barand replied to edfou's topic in PHP Coding Help
What do the posted day and time look like (formats)? -
Told you that earlier in reply #2!
-
Add some debugging code after the update query. if(!$result) { echo 'Redeemer code is not valid, please try again.'; echo '<br>' . $sql . '<br>' . mysql_error(); }