Jump to content

web_master

Members
  • Posts

    419
  • Joined

  • Last visited

About web_master

  • Birthday 07/12/1966

Contact Methods

Profile Information

  • Gender
    Male
  • Location
    Serbia

web_master's Achievements

Advanced Member

Advanced Member (4/5)

0

Reputation

  1. As I see there is a many ways to use mysqli in request data from database. I try simple to "rename" mysql_ to mysqli_ but it not work. Somewhere I need to connect to the database too, $dbConnect. This is a problem, how can I do this...
  2. Hi, I got a problem with pagination. I got a script but the problem is that I use the connection to database with "mysqli" NOT "mysql". Im newbe with mysqli and I dont know how can I change the pagination script to work. <?php $dbConnect= mysqli_connect('localhost', 'user', 'password') or die('Cant connect'); mysqli_select_db($dbConnect, 'database') or die('Cant connect to database'); mysqli_set_charset($dbConnect, "utf8"); ?> And this is a script for pagination <?php $limit = 4; $sql = "select count(c_vesti_id) from c_vesti"; $c = array_shift(mysql_fetch_row(mysql_query($sql))); $maxpage = ceil($c / $limit); $page = isset($_GET['page']) ? abs((int)$_GET['page']) : 1; if ($page <= 0) { $page = 1; } else if ($page >= $maxpage) { $page = $maxpage; } $offset = ($page-1) * $limit; $query = mysql_query("select * from c_vesti limit $offset, $limit "); while ($row = mysql_fetch_assoc($query)) { print $row['c_vesti_naslov']."<br />"; } // $linklimit = 4; $linklimit2 = $linklimit / 2; $linkoffset = ($page > $linklimit2) ? $page - $linklimit / 2 : 0; $linkend = $linkoffset+$linklimit; if ($maxpage - $linklimit2 < $page) { $linkoffset = $maxpage - $linklimit; if ($linkoffset < 0) { $linkoffset = 0; } $linkend = $maxpage; } if ($page > 1) { print "<a href='?page=".($page-1)."'>Back</a> "; } for ($i=1+$linkoffset; $i <= $linkend and $i <= $maxpage; $i++) { $style = ($i == $page) ? "color: black;" : "color: blue;"; print "<a href='?page=$i' style='$style'>[$i]</a> "; } if ($page < $maxpage) { print "<a href='?page=".($page+1)."'>Forward</a>"; } ?> Thanks in advanced for help T
  3. Hi, I don't know what amI do wrong. I have 3 tables, (authors, text, kategories). I want to print every group names from database and + 3 text below kategory name. After first record (text) separately two more (next) records. With this code I give only the first category with 3 text... Please if You can help me.... <?php /* SELECT FROM DATABASE */ $QuerySelect = ' SELECT c_kat.c_kat_onoff, c_kat.c_kat_delete, c_kat.c_kat_order, c_autor.c_autor_onoff, c_autor.c_autor_delete, c_autor.c_autor_prezime, c_autor.c_autor_ime, c_autor.c_autor_id, c_kat.c_kat_id, c_kat.c_kat_ime, c_vesti.c_vesti_id, c_vesti.c_vesti_date, c_vesti.c_vesti_sat, c_vesti.c_vesti_min, c_vesti.c_vesti_naslov, c_vesti.c_vesti_text, c_vesti.c_vesti_kat, c_vesti.c_vesti_autor, c_vesti.c_vesti_onoff, c_vesti.c_vesti_delete FROM c_vesti INNER JOIN c_kat ON c_kat.c_kat_id = c_vesti.c_vesti_kat INNER JOIN c_autor ON c_autor.c_autor_id = c_vesti.c_vesti_autor WHERE `c_vesti_onoff` = 1 AND `c_vesti_delete` = 0 ORDER BY `c_kat_order` ASC, `c_vesti_date` DESC, `c_vesti_sat` DESC, `c_vesti_min` DESC, `c_vesti_id` ASC LIMIT 3 '; $query_select = mysqli_query($dbConnect, $QuerySelect) or die (mysqli_error($dbConnect)); if(!$query_select){ echo mysqli_error($dbConnect); exit; } while($request = mysqli_fetch_array($query_select)) { $group_by_cat[$request['c_kat_ime']][] = $request; } foreach($group_by_cat as $group => $rows) { echo '<div class="catcolor">' . $group . '</div>'; // Category name $first_rec = true; foreach($rows as $row) { if ($first_rec) { // first record echo '<div>First text headline - ', $row['c_vesti_naslov'], '</div>'; $first_rec = false; } else { // other records echo '<div>Other text headline -', $row['c_vesti_naslov'], '</div>'; } } } ?>
×
×
  • 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.