Jump to content

Barand

Moderators
  • Content Count

    20,897
  • Joined

  • Last visited

  • Days Won

    491

Barand last won the day on July 1

Barand had the most liked content!

Community Reputation

1,523 Excellent

About Barand

  • Rank
    Sen . ( ile || sei )

Profile Information

Recent Profile Visitors

63,541 profile views
  1. @Jokeh There's a good chance that the question is no longer relevant after nearly 2 1/2 years
  2. Ensure users have to log in before they can vote so you know their user_id. When they vote, store the poll_id and user_id. Put a unique constraint on (poll_id, user_id) so that combination can not be added twice.
  3. Fixed. What editor are you using? <?php include 'functions.php'; // Connect to MySQL $pdo = pdo_connect_mysql(); // If the GET request "id" exists (poll id)... if (isset($_GET['id'])) { // MySQL query that selects the poll records by the GET request "id" $stmt = $pdo->prepare('SELECT * FROM polls WHERE id = ?'); $stmt->execute([$_GET['id']]); // Fetch the record $poll = $stmt->fetch(PDO::FETCH_ASSOC); // Check if the poll record exists with the id specified if ($poll) { // MySQL query that selects all the poll answers $stmt = $pdo->prepare('SELECT * FROM poll_answers WHERE poll_id = ?'); $stmt->execute([$_GET['id']]); // Fetch all the poll anwsers $poll_answers = $stmt->fetchAll(PDO::FETCH_ASSOC); // If the user clicked the "Vote" button... if (isset($_POST['poll_answer'])) { // Update and increase the vote for the answer the user voted for $stmt = $pdo->prepare('UPDATE poll_answers SET votes = votes +1 WHERE id = ?'); $stmt->execute([$_POST['poll_answer']]); // Redirect user to the result page header ('Location: result.php?id=' . $_GET['id']); exit; } } else { die ('Poll with that ID does not exist.'); } } else { die ('No poll ID specified.'); } ?> <?=template_header('Poll Vote')?> <div class="content poll-vote"> <h2><?=$poll['title']?></h2> <p><?=$poll['des']?></p> <form action="vote.php?id=<?=$_GET['id']?>" onSubmit="disable()" method="post"> <?php for ($i = 0; $i < count($poll_answers); $i++): ?> <label> <input type="radio" name="poll_answer" value="<?=$poll_answers[$i]['id']?>" <?=$i == 0 ? ' checked' : ''?>> <?=$poll_answers[$i]['title']?> </label> <?php endfor; ?> <div> <input type="submit" name="submit" value="Vote"> <a href="result.php?id=<?=$poll['id']?>">View Result</a> </div> </form> </div> <?=template_footer()?>
  4. I created an extra table to define which category the values were in mysql> select * from catval; +-----+------+ | val | cat | +-----+------+ | 1 | 4 | | 2 | 4 | | 3 | 4 | | 4 | 4 | | 5 | 3 | | 6 | 3 | | 7 | 2 | | 8 | 2 | | 9 | 1 | | 10 | 1 | +-----+------+ then $sql = "SELECT a.cat as cata , b.cat as catb FROM datatb d JOIN catval a ON d.grpa = a.val JOIN catval b ON d.grpb = b.val "; $result = $db->query($sql); //categories $cat = [ 4 => ['name'=>'1:4', 'recs'=>[]], 3 => ['name'=>'5:6', 'recs'=>[]], 2 => ['name'=>'7:8', 'recs'=>[]], 1 => ['name'=>'9:10','recs'=>[]] ]; $n = 0; while ($row = $result->fetch_assoc()) { $cat[$row['cata']]['recs'][$n][] = $row['cata']; $cat[$row['catb']]['recs'][$n][] = $row['catb']; $n++; } // the output echo "<table border='1' style='width:500px; border-collapse:collapse;'>"; foreach ($cat as $c) { echo "<tr><th>{$c['name']}</th>"; for ($i=0; $i<$n; $i++) { echo '<td style="text-align:center;">' . (isset($c['recs'][$i]) ? join(',', $c['recs'][$i]) : '&ndash;') . "</td>"; } echo "</tr>\n"; } echo "</table>\n";
  5. Why don't you reveal the data in the datatb table so we can see the input. Then show us what the output should look like from that data. That way we might able to see the path from one to the other.
  6. Are you sure you have correct path - those names don't have much in common with the sample filenames that you posted earlier. Given the volume, it will better to chunk the $names array and add 1000 records per query. // populate the drawings table $chunks = array_chunk($names, 1000); foreach ($chunks as $ch) { $db->exec("INSERT IGNORE INTO drawings (drawing) VALUES " . join(',', $ch)); }
  7. $db should be a valid PDO connection. Change to $pdo if that's yours.
  8. Is this faster? $db->exec("DROP TABLE IF EXISTS drawings"); $db->exec("CREATE TABLE drawings (drawing varchar(20) not null PRIMARY KEY)"); $files = glob('files/*.*'); foreach ($files as $f) { $names[] = "('" . pathinfo($f, PATHINFO_FILENAME) . "')"; } // populate the drawings table $db->exec("INSERT IGNORE INTO drawings (drawing) VALUES " . join(',', $names)); // now delete those drawings NOT found in production table $db->exec("DELETE d FROM drawings d LEFT JOIN production_data p ON locate(d.drawing, p.description) WHERE p.description IS NULL; ");
  9. perhaps $table .= join(',', $columnValue);
  10. I think I'd prefer to see some of the data you are dealing with first. What does the data in drawings_pdf_files and production_data tables look like (few sample records)? What is the structure of production data table?
  11. I think he wants $start = ($page - 1) * $limit The hard-coded 50 will give problems if $limit becomes something other than 50.
  12. "sans regex" method <?php $str = "CONOCO 1'10x8 VC DF TP SGN||PRINCIPAL ILLUMINATION||ENG: CO3028TP_0VPR||DWG: CO200428||TO BE: DYED DIESEL (SPEC)||"; $result = ''; $link = 'DWG: <a href="http://www.domain.com?drawing=#">#</a>'; $p1 = $p2 = 0; while (($p1 = strpos($str, 'DWG:', $p2)) !== false) { $result .= substr($str, $p2, $p1 - $p2); $p2 = strpos($str, '||', $p1+4); $drwg = trim(substr($str, $p1+4, $p2 - ($p1 + 4))); $result .= str_replace('#', $drwg, $link); } $result .= substr($str, $p2); echo $str . '<br>' . $result; ?>
  13. You could roll your own. function twoColorCircle($a, $b, $sz) { $out = "<svg width='$sz' height='$sz' viewBox='0 0 1000 1000'> <linearGradient id='grad2' x1='0' y1='0' x2='1' y2='0'> <stop offset='0%' style='stop-color:$a'/> <stop offset='50%' style='stop-color:$a'/> <stop offset='50%' style='stop-color:$b'/> <stop offset='100%' style='stop-color:$b'/> </linearGradient> "; $c = 500; $r = 499; $out .= "<circle cx='$c' cy='$c' r='$r' fill='url(#grad2)' stroke='#000' /> </svg>"; return $out; } foreach ([16,32,64,128,256] as $sz) echo twoColorCircle('#5fc75d' , '#f19e2d' , $sz); echo '<br>'; foreach (['16em','8em','4em','2em','1em'] as $sz) echo twoColorCircle('#5fc75d' , '#f19e2d' , $sz);
  14. Post in the "job Offerings" section of this site and provide contact information.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.