Jump to content
florin1000

[help]php

Recommended Posts

Salutare...sunt nou pe site...si incepator in php am si eu un site de facut... mai exact vreu sa afiseze niste texte din baza de date ... dar codul e luat de undeva si nu il inteleg ...el merge dar imi arata decat 2 randuri din el...eu as vrea sa fie mai multe...am incercat sa adaug comanda dar nu a mers...

 <?php 

// Debugging
if(isset($debug))
error_reporting(E_ALL);

// FUNCTIONS
// Get setting from database. Kind of inefficient.
// In the next version, make sure all the variables are fetched at once, so only one call will have to be made to the database.

function get_setting($name, $type = 'option'){
global $tablesettings, $setting;


if(isset($setting[$name])){
return $setting[$name];

} else {
$query = mysql_query ("SELECT value from `$tablesettings` WHERE name='$name' AND type='$type' LIMIT 1");
if(mysql_num_rows($query)){
$set = mysql_fetch_array($query);
$setting[$name] = $set['value'];
return $setting[$name];
}
}
}

// Create pagination
function pagination($query, $page){
global $_GET;
$total_pages = ceil(mysql_num_rows($query)/get_setting('numperpage'));
$x = (isset($_GET['x'])) ? $_GET['x'] : null;
if($total_pages != 1){
echo("<ul class='pagination'>");
for($i = 0; $i < $total_pages; $i++) {
$page_no = $i + 1;
if($i == $page){
echo "<li class='current'><a href=\"".$_SERVER['PHP_SELF']."?page=$i&x=$x\" class=\"current\">$page_no</a>";
} else {
echo "[*]<a href=\"".$_SERVER['PHP_SELF']."?page=$i&x=$x\">$page_no</a>";
}
}
echo('[/list]<br style="clear: left;" />');
}
}



// Query
$query = mysql_query("SELECT * FROM `$tablefaqs` WHERE id_cat='0'");

// Pagination
$page = (isset($_GET['page'])) ? $_GET['page'] : null;
pagination($query, $page);

if(isset($_GET['s'])){
if(strlen($_GET['s']) > 3){

}

// Normal queries.
} elseif($page == 0){
$select = mysql_query("SELECT * from $tablefaqs ORDER BY id_user asc LIMIT ".get_setting('numperpage')) or die(mysql_error());
} else {
$start_limit = get_setting('numperpage') * $page;
$select = mysql_query("SELECT * from $tablefaqs ORDER BY id_user asc LIMIT $start_limit, ".get_setting('numperpage')) or die(mysql_error());
}

// Empty database.
if(mysql_num_rows($select) == 0){
echo("Sorry, no questions, answers or names matched this search query.");

// Not empty database.
} else {
// Echo template.
while($qa = mysql_fetch_array($select)) {

$template = get_setting('faqtemp');
$template = str_replace('%question%',$qa['1'],$template);
$template = str_replace('%answer%',$qa['limbi'],$template);
$template = str_replace('%name%',$qa['localitatea'],$template);
$template = str_replace('%email%','',$template);
echo($template);
}

}

?>

pls am stat 3 zile sa il inteleg si asta e cea mai buna forma pe care am gasit-o

PS nu mai trebuie ms...am gasit :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...