-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
fetch_all() returns and array of the returned rows which you would then loop through, as in your last posted topic. If you only expect a single row for the selected country then it is $r = $connection->query($sql); $result = $r->fetch_assoc(); echo $result['Wages'];
-
Getting value's of dropdown from MySql not working
Barand replied to brokenglass's topic in PHP Coding Help
see what error you have $r = $connection->query($sql) or die($connection->error); -
Getting value's of dropdown from MySql not working
Barand replied to brokenglass's topic in PHP Coding Help
Having defined the query string you need to execute the query then get the results. Also, your mysqli connection needs the dbname as the 4th argument. $connection = new mysqli($servername,$username,$password,$dbname); $sql = "SELECT Country from w "; $r = $connection->query($sql); $result = $r->fetch_all(MYSQLI_ASSOC); echo '<select>'; foreach($result as $res) { echo '<option value="'.$res['Country'].'">' . $res['Country'] . '</option>'; } echo '</select>'; edit: Nearly missed it - don't quote table and column names, and it does help to use meaningful names rather than just w -
$json is not defined within the function. You need to pass it as an additional argument.
-
If you do not specify a method, it defaults to GET edit: Please use code tags when posting code, or use the <> button
-
Oops! Well spotted. Sorry about that. MySql Workbench defaults to varchar(45) and I forgot to change that one.
-
From what you have said it seems there is a two step process A video is submitted by the user You vet the video for acceptance and it is then loaded to the site and video table updated On that second step you could write the record for the video to the search table.
-
That is "referential integrity"
-
-
That means the query has failed. Check db connection and also field and table names in the query. Changing $res = $db->query($sql); to $res = $db->query($sql) or die($db->error); should help to isolate the error
-
Can a person belong to more than one group?
-
Easiest is to use a function to which you pass the users current level function auth_level_options ($db, $user_level) { $sql = "SELECT auth_level , descrip FROM Auth ORDER BY auth_level"; $res = $db->query($sql); $opts = "<select name='flag>" while (list($level,$desc) = $res->fetch_row()) { $sel = $level == $user_level ? 'selected="selected"' : ''; $opts .= "<option value='$level' $sel>$desc</option>"; } $opts .= "</select>\n"; return $opts; } then where you want the dropdown echo auth_level_options($dbconn, $current_user_level);
-
Is this what you are trying to do blake.html <!DOCTYPE HTML > <html> <head> <meta name="author" content="Barand"> <meta name="creation-date" content="11/05/2014"> <title>Example</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type='text/javascript'> $().ready(function() { $("#button").click(function() { var name = "test"; $.get( "blake.php", {"name":name}, function(data) { $.each(data, function(k,v){ $("#click").append(k + " : " + v + "\n"); }) $("#click").append("--------------------\n"); }, "json" ) }) $("#clear").click(function() { $("#click").html(""); }) }) </script> </head> <body> <textarea cols='20' rows='15' id='click'></textarea> <input type="button" name="button" id="button" value="Click me"> <input type="button" name="clear" id="clear" value="Clear"> </body> </html> blake.php (called via ajax) <?php session_start(); if (isset($_GET['name'])) { $userAnswer = $_GET['name']; if (isset($_SESSION['test'][$userAnswer])) { $_SESSION['test'][$userAnswer]['var1']++; } else { $_SESSION['test'][$userAnswer] = array('var1'=>1, 'var2'=>2); } echo json_encode($_SESSION['test'][$userAnswer]); } else echo ''; ?>
-
Depends on the volume exported 1000 or less read from server1 table store in array connect to second server insert from the array more than 1000 read from server1 table write to a csv file connect to second server use LOAD DATA INFILE to insert records
-
I don't see why you need a cron job. Make the writing of the "search" record part of the acceptance process. You just need a one-off process to create the table from your existing video records. Also you don't have to merge the fields into one to have a full text index. You can index multiple fields.
-
One table will suffice if you use NULL to represent no parent as Jaques stated CREATE TABLE `test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `col1` int(11) DEFAULT NULL, `parent_id` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `fk1` (`parent_id`), CONSTRAINT `fk1` FOREIGN KEY (`parent_id`) REFERENCES `test` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION ) mysql> select * from test; +----+------+-----------+ | id | col1 | parent_id | +----+------+-----------+ | 1 | 222 | NULL | (top level, no parent) | 2 | 333 | 1 | | 3 | 44 | NULL | (top level, no parent) | 4 | 22 | 1 | | 5 | 32 | 2 | | 6 | 21 | 3 | | 7 | 43 | 3 | +----+------+-----------+ 7 rows in set (0.00 sec) mysql> DELETE FROM test WHERE id = 1; Query OK, 1 row affected (0.00 sec) mysql> select * from test; +----+------+-----------+ | id | col1 | parent_id | +----+------+-----------+ | 3 | 44 | NULL | | 6 | 21 | 3 | | 7 | 43 | 3 | +----+------+-----------+ 3 rows in set (0.00 sec)
-
You don't seem to be returning a json encoded array, rather a list of json encoded variables instead, which is just a list of those variable values So you are return something like "12"; To return a json encoded array use echo json_encode($_SESSION['test'][$username]) which will return {"var1":2,"var2":3} Alternatively, change the ajax request to expect plain "text", which is what you are returning.
-
Yes but, unfortunately, mine wasn't as ambitious as yours I restricted them to items in the database
-
You obviously like typing if(isset($_POST['name']) && isset($_POST['name2'])) { echo json_encode(array($_POST['name'], $_POST['name2']) ); }
-
you could change +----------------+ | video (innodb) | +----------------+ | video_id | | title | | description | | author | | duration | | etc | +----------------+ to +----------------+ +----------------+ | video (innodb) | | search (myisam)| +----------------+ +----------------+ | video_id |--------| video_id | | | | title | (fulltext) | | | description | (fulltext) | author | +----------------+ | duration | | etc | +----------------+ then SELECT .... FROM video INNER JOIN search USING (video_id) WHERE MATCH ... AGAINST ...
-
Disregard that last post. I ran it few more times and the WHERE made no difference, in fact it was slower on occasions
-
This is from the code you posted Why don't you just use the same method to center or right-align your other fields?
-
Here's an example of how your first two queries would be combined. SELECT * FROM tblOperators o LEFT JOIN tblUserPayments p ON p.OperatorID = 0.OperatorID AND PaymentStatus='OK' AND PaymentDate LIKE '$currentDate%' WHERE OperatorLocale = 'USA' and OperatorStatus = 'ACTIVE' and Team = 'RENEWALS' Do not use SELECT * in your queries, specify the columns you need. You could combine the others too, probably, but that would mean my reverse engineering your table structures and all I know is that all your tables contain " * ".